Changeset 463 for branches/highdpi/Packages/Common/Translator.pas
- Timestamp:
- Nov 29, 2023, 2:35:44 PM (12 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/Common/Translator.pas
r462 r463 1 unit UTranslator; 2 3 {$mode Delphi}{$H+} 1 unit Translator; 4 2 5 3 interface 6 4 7 5 uses 8 UDpiControls, Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs,LazFileUtils, LazUTF8,9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType,10 LCLVersion ;6 UDpiControls, Classes, SysUtils, Forms, ExtCtrls, Controls, LazFileUtils, LazUTF8, 7 Translations, TypInfo, Dialogs, FileUtil, LCLProc, Languages, LCLType, 8 LCLVersion, Generics.Collections; 11 9 12 10 type 13 11 THandleStringEvent = function (AValue: string): string of object; 12 13 TPoFiles = class(TObjectList<TPOFile>) 14 end; 14 15 15 16 { TComponentExcludes } … … 24 25 { TComponentExcludesList } 25 26 26 TComponentExcludesList = class(TObjectList )27 TComponentExcludesList = class(TObjectList<TComponentExcludes>) 27 28 function FindByClassType(AClassType: TClass): TComponentExcludes; 28 29 procedure DumpToStrings(Strings: TStrings); … … 36 37 FOnAutomaticLanguage: THandleStringEvent; 37 38 FOnTranslate: TNotifyEvent; 38 FP OFilesFolder: string;39 FP OFiles: TObjectList; // TObjectList<TPOFile>;39 FPoFilesFolder: string; 40 FPoFiles: TPoFiles; 40 41 function GetLocale: string; 41 42 function GetLocaleShort: string; … … 50 51 public 51 52 ComponentExcludes: TComponentExcludesList; 52 Languages: TLanguage List;53 Languages: TLanguages; 53 54 procedure Translate; 54 procedure LanguageListToStrings(Strings: TStrings );55 procedure LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 55 56 procedure TranslateResourceStrings(PoFileName: string); 56 57 procedure TranslateUnitResourceStrings(UnitName: string; PoFileName: string); … … 63 64 destructor Destroy; override; 64 65 published 65 property POFilesFolder: string read FP OFilesFolder write SetPOFilesFolder;66 property POFilesFolder: string read FPoFilesFolder write SetPOFilesFolder; 66 67 property Language: TLanguage read FLanguage write SetLanguage; 67 68 property OnTranslate: TNotifyEvent read FOnTranslate write FOnTranslate; … … 71 72 72 73 procedure Register; 74 73 75 74 76 implementation … … 117 119 destructor TComponentExcludes.Destroy; 118 120 begin 119 PropertyExcludes.Free;120 inherited Destroy;121 FreeAndNil(PropertyExcludes); 122 inherited; 121 123 end; 122 124 … … 128 130 I, J: Integer; 129 131 Po: TPoFile; 130 Item: TP OFileItem;132 Item: TPoFileItem; 131 133 begin 132 134 TranslateComponentRecursive(DpiApplication); … … 134 136 // Merge files to single translation file 135 137 try 136 Po := TP OFile.Create;137 for I := 0 to FP OFiles.Count - 1 do138 Po := TPoFile.Create; 139 for I := 0 to FPoFiles.Count - 1 do 138 140 with TPoFile(FPoFiles[I]) do 139 141 for J := 0 to Items.Count - 1 do … … 162 164 SearchMask: string; 163 165 begin 164 FP OFiles.Clear;166 FPoFiles.Clear; 165 167 if Assigned(FLanguage) then 166 168 try 167 169 LocaleShort := GetLocaleShort; 168 //ShowMessage(ExtractFileDir( DpiApplication.ExeName) +170 //ShowMessage(ExtractFileDir(Application.ExeName) + 169 171 // DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po'); 170 172 SearchMask := '*'; … … 177 179 if FileExists(FileName) and ( 178 180 ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or 179 (LocaleShort <> '')) then FP OFiles.Add(TPOFile.Create(FileName));181 (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName)); 180 182 end; 181 183 finally … … 281 283 var 282 284 Item: TClass; 283 284 285 Excludes: TComponentExcludes; 285 286 begin … … 287 288 Item := Component.ClassType; 288 289 while Assigned(Item) do begin 289 //ShowMessage(Component.Name + ', ' + Component.ClassName + ', ' + Item.ClassName + ', ' + PropertyName);290 290 Excludes := ComponentExcludes.FindByClassType(Item.ClassType); 291 291 if Assigned(Excludes) then begin … … 301 301 function TTranslator.GetLangFileDir: string; 302 302 begin 303 Result := FP OFilesFolder;303 Result := FPoFilesFolder; 304 304 if Copy(Result, 1, 1) <> DirectorySeparator then 305 305 Result := ExtractFileDir(DpiApplication.ExeName) + … … 307 307 end; 308 308 309 procedure TTranslator.LanguageListToStrings(Strings: TStrings );309 procedure TTranslator.LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 310 310 var 311 311 I: Integer; … … 313 313 begin 314 314 with Strings do begin 315 Clear; 316 for I := 0 to Languages.Count - 1 do 317 with TLanguage(Languages[I]) do 318 if Available then begin 319 ItemName := Name; 320 if Code <> '' then ItemName := ItemName + ' (' + Code + ')'; 321 AddObject(ItemName, Languages[I]); 322 end; 315 BeginUpdate; 316 try 317 Clear; 318 for I := 0 to Languages.Count - 1 do 319 with Languages[I] do 320 if Available then begin 321 ItemName := Name; 322 if WithCode and (Code <> '') then ItemName := ItemName + ' (' + Code + ')'; 323 AddObject(ItemName, Languages[I]); 324 end; 325 finally 326 EndUpdate; 327 end; 323 328 end; 324 329 end; … … 342 347 if Text <> '' then begin 343 348 for I := 0 to FPoFiles.Count - 1 do begin 344 Result := TPoFile(FP OFiles[I]).Translate(Identifier, Text);349 Result := TPoFile(FPoFiles[I]).Translate(Identifier, Text); 345 350 if Result <> Text then Break; 346 351 end; … … 369 374 begin 370 375 LangDir := GetLangFileDir; 371 TLanguage(Languages[0]).Available := True; // Automatic376 Languages.SearchByCode('').Available := True; // Automatic 372 377 373 378 for I := 1 to Languages.Count - 1 do 374 with TLanguage(Languages[I])do begin379 with Languages[I] do begin 375 380 Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(DpiApplication.ExeName) + 376 381 '.' + Code + ExtensionSeparator + 'po') or (Code = 'en'); … … 381 386 begin 382 387 inherited; 383 FP OFiles := TObjectList.Create;388 FPoFiles := TPoFiles.Create; 384 389 ComponentExcludes := TComponentExcludesList.Create; 385 Languages := TLanguage List.Create;390 Languages := TLanguages.Create; 386 391 POFilesFolder := 'Languages'; 387 392 CheckLanguageFiles; … … 395 400 destructor TTranslator.Destroy; 396 401 begin 397 F POFiles.Free;398 Languages.Free;399 ComponentExcludes.Free;400 inherited Destroy;402 FreeAndNil(FPoFiles); 403 FreeAndNil(Languages); 404 FreeAndNil(ComponentExcludes); 405 inherited; 401 406 end; 402 407 … … 564 569 end; 565 570 566 567 571 end. 568
Note:
See TracChangeset
for help on using the changeset viewer.