Changeset 315 for trunk/Packages/Common/Translator.pas
- Timestamp:
- Jun 19, 2024, 11:15:44 PM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Translator.pas
r314 r315 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 78 78 79 implementation 80 81 uses 82 Common; 79 83 80 84 procedure Register; … … 163 167 FileList: TStringList; 164 168 I: Integer; 169 J: Integer; 165 170 LocaleShort: string; 166 171 SearchMask: string; 172 LangDirs: TStrings; 167 173 begin 168 174 FPoFiles.Clear; 169 if Assigned(FLanguage) then 170 try 175 if Assigned(FLanguage) then begin 171 176 LocaleShort := GetLocaleShort; 172 //ShowMessage(ExtractFileDir(Application.ExeName) +173 // DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po');174 177 SearchMask := '*'; 175 178 if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort; 176 SearchMask := SearchMask + '.po'; 177 FileList := FindAllFiles(GetLangFileDir, SearchMask); 178 for I := 0 to FileList.Count - 1 do begin 179 FileName := FileList[I]; 180 //FileName := FindLocaleFileName('.po'); 181 if FileExists(FileName) and ( 182 ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', 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; … … 290 299 Item := Component.ClassType; 291 300 while Assigned(Item) do begin 292 //ShowMessage(Component.Name + ', ' + Component.ClassName + ', ' + Item.ClassName + ', ' + PropertyName);293 301 Excludes := ComponentExcludes.FindByClassType(Item.ClassType); 294 302 if Assigned(Excludes) then begin … … 302 310 end; 303 311 304 function TTranslator.GetLangFileDir: string; 305 begin 306 Result := FPoFilesFolder; 307 if Copy(Result, 1, 1) <> DirectorySeparator then 308 Result := ExtractFileDir(Application.ExeName) + 309 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 then 325 Result[I] := ExtractFileDir(Application.ExeName) + 326 DirectorySeparator + Result[I]; 327 end; 310 328 end; 311 329 … … 374 392 var 375 393 I: Integer; 376 LangDir: string; 377 begin 378 LangDir := GetLangFileDir; 394 J: Integer; 395 LangDirs: TStrings; 396 begin 397 LangDirs := GetLangFileDirs; 379 398 Languages.SearchByCode('').Available := True; // Automatic 380 399 381 400 for I := 1 to Languages.Count - 1 do 382 401 with Languages[I] do begin 383 Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) + 384 '.' + Code + ExtensionSeparator + 'po') or (Code = 'en'); 385 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; 386 411 end; 387 412 … … 572 597 end; 573 598 574 575 599 end. 576
Note:
See TracChangeset
for help on using the changeset viewer.