Changeset 75 for trunk/Directories.pas


Ignore:
Timestamp:
Jan 15, 2017, 5:20:33 PM (8 years ago)
Author:
chronos
Message:
  • Added: By default interface language should be selected according system language.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Directories.pas

    r64 r75  
    66var
    77  HomeDir, DataDir: string;
    8   LocaleCode: string;
     8  LocaleCode: string = '';
     9  LocaleCodeAuto: string = '';
    910
    1011function LocalizedFilePath(const Path: string): string;
     
    1415
    1516uses
    16   LCLIntf, LCLType, SysUtils, FileUtil;
     17  FileUtil, LCLIntf, LCLType, LCLProc, LazUTF8, SysUtils;
    1718
    1819var
    1920  AppDataDir: string;
    2021  src, dst: TSearchRec;
     22
    2123
    2224function DirectoryExists(path: string): boolean;
     
    2729end;
    2830
     31function GetLocale: string;
     32var
     33  Lang: string;
     34  I: Integer;
     35  T: string;
     36begin
     37  // Win32 user may decide to override locale with LANG variable.
     38  Lang := GetEnvironmentVariableUTF8('LANG');
     39
     40  if Lang = '' then begin
     41      for i := 1 to Paramcount - 1 do
     42        if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
     43          (ParamStrUTF8(i) = '--lang') then
     44          Lang := ParamStrUTF8(i + 1);
     45  end;
     46  if Lang = '' then begin
     47    LazGetLanguageIDs(Lang, T);
     48    Lang := Copy(Lang, 1, 2);
     49  end;
     50
     51  Result := Lang;
     52end;
     53
    2954function LocalizedFilePath(const Path: string): string;
     55var
     56  LocaleCodeDir: string;
    3057begin
    31   if LocaleCode <> '' then begin
    32     Result := HomeDir + 'Localization' + DirectorySeparator + LocaleCode + DirectorySeparator + Path;
     58  if LocaleCode = '' then begin
     59    if LocaleCodeAuto = '' then LocaleCodeAuto := GetLocale;
     60    LocaleCodeDir := LocaleCodeAuto;
     61  end else LocaleCodeDir := LocaleCode;
     62
     63  if LocaleCode <> 'en' then begin
     64    Result := HomeDir + 'Localization' + DirectorySeparator + LocaleCodeDir + DirectorySeparator + Path;
    3365    if not FileExists(Result) then
    3466      Result := HomeDir + Path;
Note: See TracChangeset for help on using the changeset viewer.