Ignore:
Timestamp:
Jun 19, 2024, 11:15:44 PM (4 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

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

    r314 r315  
    1 unit UTranslator;
    2 
    3 {$mode delphi}{$H+}
     1unit Translator;
    42
    53interface
    64
    75uses
    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;
    119
    1210type
    1311  THandleStringEvent = function (AValue: string): string of object;
    1412
    15   TPoFiles = class(TFPGObjectList<TPOFile>)
     13  TPoFiles = class(TObjectList<TPOFile>)
    1614  end;
    1715
     
    2725  { TComponentExcludesList }
    2826
    29   TComponentExcludesList = class(TFPGObjectList<TComponentExcludes>)
     27  TComponentExcludesList = class(TObjectList<TComponentExcludes>)
    3028    function FindByClassType(AClassType: TClass): TComponentExcludes;
    3129    procedure DumpToStrings(Strings: TStrings);
     
    5048    procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo);
    5149    function IsExcluded(Component: TPersistent; PropertyName: string): Boolean;
    52     function GetLangFileDir: string;
     50    function GetLangFileDirs: TStrings;
    5351  public
    5452    ComponentExcludes: TComponentExcludesList;
     
    7371  end;
    7472
     73const
     74  PoExt = '.po';
     75
    7576procedure Register;
    7677
    7778
    7879implementation
     80
     81uses
     82  Common;
    7983
    8084procedure Register;
     
    163167  FileList: TStringList;
    164168  I: Integer;
     169  J: Integer;
    165170  LocaleShort: string;
    166171  SearchMask: string;
     172  LangDirs: TStrings;
    167173begin
    168174  FPoFiles.Clear;
    169   if Assigned(FLanguage) then
    170   try
     175  if Assigned(FLanguage) then begin
    171176    LocaleShort := GetLocaleShort;
    172     //ShowMessage(ExtractFileDir(Application.ExeName) +
    173     //  DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po');
    174177    SearchMask := '*';
    175178    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;
    187196  end;
    188197end;
     
    290299  Item := Component.ClassType;
    291300  while Assigned(Item) do begin
    292     //ShowMessage(Component.Name + ', ' + Component.ClassName + ', ' + Item.ClassName + ', ' + PropertyName);
    293301    Excludes := ComponentExcludes.FindByClassType(Item.ClassType);
    294302    if Assigned(Excludes) then begin
     
    302310end;
    303311
    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;
     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;
    310328end;
    311329
     
    374392var
    375393  I: Integer;
    376   LangDir: string;
    377 begin
    378   LangDir := GetLangFileDir;
     394  J: Integer;
     395  LangDirs: TStrings;
     396begin
     397  LangDirs := GetLangFileDirs;
    379398  Languages.SearchByCode('').Available := True; // Automatic
    380399
    381400  for I := 1 to Languages.Count - 1 do
    382401  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;
    386411end;
    387412
     
    572597end;
    573598
    574 
    575599end.
    576 
Note: See TracChangeset for help on using the changeset viewer.