Ignore:
Timestamp:
Jun 28, 2024, 11:08:43 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Translator.pas

    r29 r30  
    1 unit UTranslator;
     1unit Translator;
    22
    33interface
     
    55uses
    66  Classes, SysUtils, Forms, ExtCtrls, Controls, LazFileUtils, LazUTF8,
    7   Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType,
     7  Translations, TypInfo, Dialogs, FileUtil, LCLProc, Languages, LCLType,
    88  LCLVersion, Generics.Collections;
    99
     
    4848    procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo);
    4949    function IsExcluded(Component: TPersistent; PropertyName: string): Boolean;
    50     function GetLangFileDir: string;
     50    function GetLangFileDirs: TStrings;
    5151  public
    5252    ComponentExcludes: TComponentExcludesList;
     
    7171  end;
    7272
     73const
     74  PoExt = '.po';
     75
    7376procedure Register;
    7477
    7578
    7679implementation
     80
     81uses
     82  Common;
    7783
    7884procedure Register;
     
    161167  FileList: TStringList;
    162168  I: Integer;
     169  J: Integer;
    163170  LocaleShort: string;
    164171  SearchMask: string;
     172  LangDirs: TStrings;
    165173begin
    166174  FPoFiles.Clear;
    167   if Assigned(FLanguage) then
    168   try
     175  if Assigned(FLanguage) then begin
    169176    LocaleShort := GetLocaleShort;
    170     //ShowMessage(ExtractFileDir(Application.ExeName) +
    171     //  DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po');
    172177    SearchMask := '*';
    173178    if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort;
    174     SearchMask := SearchMask + '.po';
    175     FileList := FindAllFiles(GetLangFileDir, SearchMask);
    176     for I := 0 to FileList.Count - 1 do begin
    177       FileName := FileList[I];
    178       //FileName := FindLocaleFileName('.po');
    179       if FileExists(FileName) and (
    180       ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or
    181       (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName));
    182     end;
    183   finally
    184     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;
    185196  end;
    186197end;
     
    299310end;
    300311
    301 function TTranslator.GetLangFileDir: string;
    302 begin
    303   Result := FPoFilesFolder;
    304   if Copy(Result, 1, 1) <> DirectorySeparator then
    305     Result := ExtractFileDir(Application.ExeName) +
    306       DirectorySeparator + Result;
     312function TTranslator.GetLangFileDirs: TStrings;
     313var
     314  I: Integer;
     315begin
     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;
    307328end;
    308329
     
    371392var
    372393  I: Integer;
    373   LangDir: string;
    374 begin
    375   LangDir := GetLangFileDir;
     394  J: Integer;
     395  LangDirs: TStrings;
     396begin
     397  LangDirs := GetLangFileDirs;
    376398  Languages.SearchByCode('').Available := True; // Automatic
    377399
    378400  for I := 1 to Languages.Count - 1 do
    379401  with Languages[I] do begin
    380     Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) +
    381       '.' + Code + ExtensionSeparator + 'po') 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;
    383411end;
    384412
     
    569597end;
    570598
    571 
    572599end.
    573 
Note: See TracChangeset for help on using the changeset viewer.