Ignore:
Timestamp:
Mar 22, 2018, 8:31:19 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Update Common and CollTranslator packages to fix build under Lazarus 1.8.
  • Fixed: Some memory leaks.
File:
1 edited

Legend:

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

    r10 r15  
    66
    77uses
    8   Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs,
     8  Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, LazFileUtils, LazUTF8,
    99  Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType;
    1010
     
    4646    procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo);
    4747    function IsExcluded(Component: TPersistent; PropertyName: string): Boolean;
     48    function GetLangFileDir: string;
    4849  public
    4950    ComponentExcludes: TComponentExcludesList;
     
    150151  I: Integer;
    151152  LocaleShort: string;
     153  SearchMask: string;
    152154begin
    153155  FPOFiles.Clear;
     
    157159    //ShowMessage(ExtractFileDir(Application.ExeName) +
    158160    //  DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po');
    159     FileList := FindAllFiles(ExtractFileDir(UTF8Encode(Application.ExeName)) +
    160       DirectorySeparator + FPOFilesFolder, '*.' + LocaleShort + '.po');
     161    SearchMask := '*';
     162    if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort;
     163    SearchMask := SearchMask + '.po';
     164    FileList := FindAllFiles(GetLangFileDir, SearchMask);
    161165    for I := 0 to FileList.Count - 1 do begin
    162166      FileName := FileList[I];
    163167      //FileName := FindLocaleFileName('.po');
    164       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));
    165171    end;
    166172  finally
     
    174180  FPoFilesFolder := AValue;
    175181  ReloadFiles;
     182  CheckLanguageFiles;
    176183end;
    177184
     
    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;
     
    382400begin
    383401  // Win32 user may decide to override locale with LANG variable.
    384   Lang := GetEnvironmentVariableUTF8('LANG');
     402  Lang := GetEnvironmentVariable('LANG');
    385403
    386404  // Use user selected language
     
    390408  if Lang = '' then begin
    391409    for i := 1 to Paramcount - 1 do
    392       if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    393         (ParamStrUTF8(i) = '--lang') then
    394         Lang := ParamStrUTF8(i + 1);
     410      if (ParamStr(i) = '--LANG') or (ParamStr(i) = '-l') or
     411        (ParamStr(i) = '--lang') then
     412        Lang := ParamStr(i + 1);
    395413  end;
    396414  if Lang = '' then
    397     LCLGetLanguageIDs(Lang, T);
     415    LazGetLanguageIDs(Lang, T);
    398416
    399417  if Assigned(Language) and (Language.Code = '') and Assigned(FOnAutomaticLanguage) then begin
    400418    Lang := FOnAutomaticLanguage(Lang);
    401419  end;
    402 
    403   if Lang = 'en' then Lang := ''; // English files are without en code
    404420
    405421  Result := Lang;
     
    423439    Exit;
    424440
    425   Result := ChangeFileExt(ParamStrUTF8(0), LCExt);
     441  Result := ChangeFileExt(ParamStr(0), LCExt);
    426442  if FileExistsUTF8(Result) then
    427443    Exit;
Note: See TracChangeset for help on using the changeset viewer.