Ignore:
Timestamp:
Dec 17, 2016, 6:33:13 PM (7 years ago)
Author:
chronos
Message:
  • Added: Main application icon.
  • Modified: Updated Command and CoolTranslator packages.
  • Added: About dialog.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CoolTranslator/UCoolTranslator.pas

    r72 r74  
    66
    77uses
    8   Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs,
    9   Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType,
    10   LazFileUtils, LazUTF8;
     8  Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, LazFileUtils, LazUTF8,
     9  Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType;
    1110
    1211type
     
    4746    procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo);
    4847    function IsExcluded(Component: TPersistent; PropertyName: string): Boolean;
     48    function GetLangFileDir: string;
    4949  public
    5050    ComponentExcludes: TComponentExcludesList;
    5151    Languages: TLanguageList;
     52    procedure Translate;
    5253    procedure LanguageListToStrings(Strings: TStrings);
    53     procedure Translate;
    5454    procedure TranslateResourceStrings(PoFileName: string);
    5555    procedure TranslateUnitResourceStrings(UnitName: string; PoFileName: string);
     
    151151  I: Integer;
    152152  LocaleShort: string;
     153  SearchMask: string;
    153154begin
    154155  FPOFiles.Clear;
     
    158159    //ShowMessage(ExtractFileDir(Application.ExeName) +
    159160    //  DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po');
    160     FileList := FindAllFiles(ExtractFileDir(UTF8Encode(Application.ExeName)) +
    161       DirectorySeparator + FPOFilesFolder, '*.' + LocaleShort + '.po');
     161    SearchMask := '*';
     162    if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort;
     163    SearchMask := SearchMask + '.po';
     164    FileList := FindAllFiles(GetLangFileDir, SearchMask);
    162165    for I := 0 to FileList.Count - 1 do begin
    163166      FileName := FileList[I];
    164167      //FileName := FindLocaleFileName('.po');
    165       if FileExistsUTF8(FileName) then FPOFiles.Add(TPOFile.Create(FileName));
     168      if FileExists(FileName) and (
     169      ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or
     170      (LocaleShort <> '')) then FPOFiles.Add(TPOFile.Create(FileName));
    166171    end;
    167172  finally
     
    175180  FPoFilesFolder := AValue;
    176181  ReloadFiles;
     182  CheckLanguageFiles;
    177183end;
    178184
     
    191197  PropInfo: PPropInfo;
    192198  PropList: PPropList;
     199  Excludes: TComponentExcludes;
    193200begin
    194201  Count := GetTypeData(Component.ClassInfo)^.PropCount;
     
    243250          if (UpperCase(PropType.Name) = 'TTRANSLATESTRING') then
    244251          //if not IsExcluded(Component, PropInfo^.Name) then
    245               SetStrProp(Component, PropInfo, TranslateText(PropInfo^.Name, GetStrProp(Component, PropInfo)));
     252              SetStrProp(Component, PropInfo, TranslateText(PropInfo^.Name, GetWideStrProp(Component, PropInfo)));
    246253        end;
    247254        tkClass: begin
     
    284291end;
    285292
     293function TCoolTranslator.GetLangFileDir: string;
     294begin
     295  Result := FPOFilesFolder;
     296  if Copy(Result, 1, 1) <> DirectorySeparator then
     297    Result := ExtractFileDir(UTF8Encode(Application.ExeName)) +
     298      DirectorySeparator + Result;
     299end;
     300
    286301procedure TCoolTranslator.LanguageListToStrings(Strings: TStrings);
    287302var
     
    316331  I: Integer;
    317332begin
     333  Result := '';
    318334  if Text <> '' then begin
    319335    for I := 0 to FPoFiles.Count - 1 do begin
     
    342358var
    343359  I: Integer;
    344 begin
     360  LangDir: string;
     361begin
     362  LangDir := GetLangFileDir;
    345363  TLanguage(Languages[0]).Available := True; // Automatic
    346364
    347365  for I := 1 to Languages.Count - 1 do
    348366  with TLanguage(Languages[I]) do begin
    349     Available := FileExistsUTF8(POFilesFolder + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) +
     367    Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) +
    350368      '.' + Code + ExtensionSeparator + 'po') or (Code = 'en');
    351369  end;
     
    381399  T: string;
    382400begin
    383   T := '';
    384 
    385401  // Win32 user may decide to override locale with LANG variable.
    386   Lang := GetEnvironmentVariableUTF8('LANG');
     402  Lang := GetEnvironmentVariable('LANG');
    387403
    388404  // Use user selected language
     
    392408  if Lang = '' then begin
    393409    for i := 1 to Paramcount - 1 do
    394       if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    395         (ParamStrUTF8(i) = '--lang') then
    396         Lang := ParamStrUTF8(i + 1);
     410      if (ParamStr(i) = '--LANG') or (ParamStr(i) = '-l') or
     411        (ParamStr(i) = '--lang') then
     412        Lang := ParamStr(i + 1);
    397413  end;
    398414  if Lang = '' then
    399     LazGetLanguageIDs(Lang, T);
     415    LCLGetLanguageIDs(Lang, T);
    400416
    401417  if Assigned(Language) and (Language.Code = '') and Assigned(FOnAutomaticLanguage) then begin
     
    403419  end;
    404420
    405   if Lang = 'en' then Lang := ''; // English files are without en code
    406 
    407421  Result := Lang;
    408422end;
     
    415429function TCoolTranslator.FindLocaleFileName(LCExt: string): string;
    416430var
     431  T: string;
    417432  Lang: string;
    418433begin
     
    424439    Exit;
    425440
    426   Result := ChangeFileExt(ParamStrUTF8(0), LCExt);
     441  Result := ChangeFileExt(ParamStr(0), LCExt);
    427442  if FileExistsUTF8(Result) then
    428443    Exit;
Note: See TracChangeset for help on using the changeset viewer.