Changeset 219 for trunk/Packages/Common/Translator.pas
- Timestamp:
- Jan 17, 2025, 9:05:54 PM (4 days ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Translator.pas
r218 r219 1 unit UTranslator; 2 3 {$mode delphi}{$H+} 1 unit Translator; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, Forms, ExtCtrls, Controls, fgl,LazFileUtils, LazUTF8,9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType,10 LCLVersion ;6 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; 14 12 15 TPoFiles = class(T FPGObjectList<TPOFile>)13 TPoFiles = class(TObjectList<TPOFile>) 16 14 end; 17 15 … … 27 25 { TComponentExcludesList } 28 26 29 TComponentExcludesList = class(T FPGObjectList<TComponentExcludes>)27 TComponentExcludesList = class(TObjectList<TComponentExcludes>) 30 28 function FindByClassType(AClassType: TClass): TComponentExcludes; 31 29 procedure DumpToStrings(Strings: TStrings); … … 50 48 procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo); 51 49 function IsExcluded(Component: TPersistent; PropertyName: string): Boolean; 52 function GetLangFileDir : string;50 function GetLangFileDirs: TStrings; 53 51 public 54 52 ComponentExcludes: TComponentExcludesList; … … 73 71 end; 74 72 73 const 74 PoExt = '.po'; 75 75 76 procedure Register; 76 77 77 const78 PoFileExt = '.po';79 80 78 81 79 implementation 80 81 uses 82 Common; 82 83 83 84 procedure Register; … … 166 167 FileList: TStringList; 167 168 I: Integer; 169 J: Integer; 168 170 LocaleShort: string; 169 171 SearchMask: string; 172 LangDirs: TStrings; 170 173 begin 171 174 FPoFiles.Clear; 172 if Assigned(FLanguage) then 173 try 175 if Assigned(FLanguage) then begin 174 176 LocaleShort := GetLocaleShort; 175 177 SearchMask := '*'; 176 178 if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort; 177 SearchMask := SearchMask + PoFileExt; 178 FileList := FindAllFiles(GetLangFileDir, SearchMask); 179 for I := 0 to FileList.Count - 1 do begin 180 FileName := FileList[I]; 181 if FileExists(FileName) and ( 182 ((LocaleShort = '') and (Pos('.', FileName) = Pos(PoFileExt, FileName))) or 183 (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName)); 184 end; 185 finally 186 FileList.Free; 179 SearchMask := SearchMask + PoExt; 180 LangDirs := GetLangFileDirs; 181 for J := 0 to LangDirs.Count - 1 do begin 182 FileList := FindAllFiles(LangDirs[J], SearchMask); 183 try 184 for I := 0 to FileList.Count - 1 do begin 185 FileName := FileList[I]; 186 //FileName := FindLocaleFileName('.po'); 187 if FileExists(FileName) and ( 188 ((LocaleShort = '') and (Pos('.', FileName) = Pos(PoExt, FileName))) or 189 (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName)); 190 end; 191 finally 192 FileList.Free; 193 end; 194 end; 195 LangDirs.Free; 187 196 end; 188 197 end; … … 245 254 I: Integer; 246 255 begin 256 247 257 // PropInfo^.Name; 248 258 // Using IsDefaultPropertyValue will tell us if we should write out … … 300 310 end; 301 311 302 function TTranslator.GetLangFileDir: string; 303 begin 304 Result := FPoFilesFolder; 305 if not FilenameIsAbsolute(Result) then 306 Result := ExtractFileDir(Application.ExeName) + DirectorySeparator + Result; 312 function TTranslator.GetLangFileDirs: TStrings; 313 var 314 I: Integer; 315 begin 316 Result := TStringList.Create; 317 Result.Delimiter := ';'; 318 Result.StrictDelimiter := True; 319 Result.DelimitedText := FPoFilesFolder; 320 321 for I := 0 to Result.Count - 1 do begin 322 Result[I] := StringReplace(Result[I], '/', DirectorySeparator, [rfReplaceAll]); 323 Result[I] := StringReplace(Result[I], '\', DirectorySeparator, [rfReplaceAll]); 324 if (Copy(Result[I], 1, 1) <> DirectorySeparator) and (Copy(Result[I], 2, 2) <> ':\') then 325 Result[I] := ExtractFileDir(Application.ExeName) + 326 DirectorySeparator + Result[I]; 327 end; 307 328 end; 308 329 … … 371 392 var 372 393 I: Integer; 373 LangDir: string; 374 begin 375 LangDir := GetLangFileDir; 394 J: Integer; 395 LangDirs: TStrings; 396 begin 397 LangDirs := GetLangFileDirs; 376 398 Languages.SearchByCode('').Available := True; // Automatic 377 399 378 400 for I := 1 to Languages.Count - 1 do 379 401 with Languages[I] do begin 380 Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) + 381 '.' + Code + PoFileExt) or (Code = 'en'); 382 end; 402 for J := 0 to LangDirs.Count - 1 do begin 403 if FileExists(LangDirs[J] + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) + 404 '.' + Code + PoExt) or (Code = 'en') then begin 405 Available := True; 406 Continue; 407 end; 408 end; 409 end; 410 LangDirs.Free; 383 411 end; 384 412 … … 468 496 469 497 begin 498 470 499 // ParamStrUTF8(0) is said not to work properly in linux, but I've tested it 471 500 Result := ExtractFilePath(ParamStrUTF8(0)) + LangID + … … 568 597 end; 569 598 570 571 599 end. 572
Note:
See TracChangeset
for help on using the changeset viewer.