Changeset 313 for trunk/Packages/Common/UTranslator.pas
- Timestamp:
- Jan 18, 2022, 10:45:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UTranslator.pas
r308 r313 1 1 unit UTranslator; 2 2 3 {$mode Delphi}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, LazFileUtils, LazUTF8,8 Classes, SysUtils, Forms, ExtCtrls, Controls, fgl, LazFileUtils, LazUTF8, 9 9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType, 10 10 LCLVersion; … … 12 12 type 13 13 THandleStringEvent = function (AValue: string): string of object; 14 15 TPoFiles = class(TFPGObjectList<TPOFile>) 16 end; 14 17 15 18 { TComponentExcludes } … … 24 27 { TComponentExcludesList } 25 28 26 TComponentExcludesList = class(T ObjectList)29 TComponentExcludesList = class(TFPGObjectList<TComponentExcludes>) 27 30 function FindByClassType(AClassType: TClass): TComponentExcludes; 28 31 procedure DumpToStrings(Strings: TStrings); … … 36 39 FOnAutomaticLanguage: THandleStringEvent; 37 40 FOnTranslate: TNotifyEvent; 38 FP OFilesFolder: string;39 FP OFiles: TObjectList; // TObjectList<TPOFile>;41 FPoFilesFolder: string; 42 FPoFiles: TPoFiles; 40 43 function GetLocale: string; 41 44 function GetLocaleShort: string; … … 50 53 public 51 54 ComponentExcludes: TComponentExcludesList; 52 Languages: TLanguage List;55 Languages: TLanguages; 53 56 procedure Translate; 54 procedure LanguageListToStrings(Strings: TStrings );57 procedure LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 55 58 procedure TranslateResourceStrings(PoFileName: string); 56 59 procedure TranslateUnitResourceStrings(UnitName: string; PoFileName: string); … … 63 66 destructor Destroy; override; 64 67 published 65 property POFilesFolder: string read FP OFilesFolder write SetPOFilesFolder;68 property POFilesFolder: string read FPoFilesFolder write SetPOFilesFolder; 66 69 property Language: TLanguage read FLanguage write SetLanguage; 67 70 property OnTranslate: TNotifyEvent read FOnTranslate write FOnTranslate; … … 71 74 72 75 procedure Register; 76 73 77 74 78 implementation … … 117 121 destructor TComponentExcludes.Destroy; 118 122 begin 119 PropertyExcludes.Free;120 inherited Destroy;123 FreeAndNil(PropertyExcludes); 124 inherited; 121 125 end; 122 126 … … 128 132 I, J: Integer; 129 133 Po: TPoFile; 130 Item: TP OFileItem;134 Item: TPoFileItem; 131 135 begin 132 136 TranslateComponentRecursive(Application); … … 134 138 // Merge files to single translation file 135 139 try 136 Po := TP OFile.Create;137 for I := 0 to FP OFiles.Count - 1 do140 Po := TPoFile.Create; 141 for I := 0 to FPoFiles.Count - 1 do 138 142 with TPoFile(FPoFiles[I]) do 139 143 for J := 0 to Items.Count - 1 do … … 162 166 SearchMask: string; 163 167 begin 164 FP OFiles.Clear;168 FPoFiles.Clear; 165 169 if Assigned(FLanguage) then 166 170 try … … 177 181 if FileExists(FileName) and ( 178 182 ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or 179 (LocaleShort <> '')) then FP OFiles.Add(TPOFile.Create(FileName));183 (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName)); 180 184 end; 181 185 finally … … 281 285 var 282 286 Item: TClass; 283 284 287 Excludes: TComponentExcludes; 285 288 begin … … 301 304 function TTranslator.GetLangFileDir: string; 302 305 begin 303 Result := FP OFilesFolder;306 Result := FPoFilesFolder; 304 307 if Copy(Result, 1, 1) <> DirectorySeparator then 305 308 Result := ExtractFileDir(Application.ExeName) + … … 307 310 end; 308 311 309 procedure TTranslator.LanguageListToStrings(Strings: TStrings );312 procedure TTranslator.LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 310 313 var 311 314 I: Integer; … … 313 316 begin 314 317 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; 318 BeginUpdate; 319 try 320 Clear; 321 for I := 0 to Languages.Count - 1 do 322 with Languages[I] do 323 if Available then begin 324 ItemName := Name; 325 if WithCode and (Code <> '') then ItemName := ItemName + ' (' + Code + ')'; 326 AddObject(ItemName, Languages[I]); 327 end; 328 finally 329 EndUpdate; 330 end; 323 331 end; 324 332 end; … … 342 350 if Text <> '' then begin 343 351 for I := 0 to FPoFiles.Count - 1 do begin 344 Result := TPoFile(FP OFiles[I]).Translate(Identifier, Text);352 Result := TPoFile(FPoFiles[I]).Translate(Identifier, Text); 345 353 if Result <> Text then Break; 346 354 end; … … 369 377 begin 370 378 LangDir := GetLangFileDir; 371 TLanguage(Languages[0]).Available := True; // Automatic379 Languages.SearchByCode('').Available := True; // Automatic 372 380 373 381 for I := 1 to Languages.Count - 1 do 374 with TLanguage(Languages[I])do begin382 with Languages[I] do begin 375 383 Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) + 376 384 '.' + Code + ExtensionSeparator + 'po') or (Code = 'en'); … … 381 389 begin 382 390 inherited; 383 FP OFiles := TObjectList.Create;391 FPoFiles := TPoFiles.Create; 384 392 ComponentExcludes := TComponentExcludesList.Create; 385 Languages := TLanguage List.Create;393 Languages := TLanguages.Create; 386 394 POFilesFolder := 'Languages'; 387 395 CheckLanguageFiles; … … 395 403 destructor TTranslator.Destroy; 396 404 begin 397 F POFiles.Free;398 Languages.Free;399 ComponentExcludes.Free;400 inherited Destroy;405 FreeAndNil(FPoFiles); 406 FreeAndNil(Languages); 407 FreeAndNil(ComponentExcludes); 408 inherited; 401 409 end; 402 410
Note:
See TracChangeset
for help on using the changeset viewer.