LCL: added a simple heruistic to find the windows local ID

git-svn-id: trunk@14924 -
This commit is contained in:
mattias 2008-04-21 21:34:36 +00:00
parent aeee3bb375
commit 764f3bb7ad
2 changed files with 33 additions and 14 deletions

View File

@ -84,10 +84,34 @@ procedure GetSupportedEncodings(List: TStrings);
implementation
{$IFDEF Windows}
uses Windows;
{$ENDIF}
var EncodingValid: boolean = false;
SystemEncoding: string = EncodingAnsi;
{$IFDEF Windows}
function GetWindowsEncoding: string;
var
Buffer : PChar;
Size : integer;
begin
Size := GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, nil, 0);
GetMem(Buffer, Size);
try
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, Buffer, Size);
Result := string(Buffer);
while (Result<>'') and (Result[1]='0') do
Result:=copy(Result,2,length(Result));
if Result<>'' then
Result:='cp'+Result;
finally
FreeMem(Buffer);
end
end;
{$ENDIF}
function GetSystemEncoding: string;
var Lang: string;
i: integer;
@ -98,7 +122,12 @@ begin
exit;
end;
{$IFDEF Windows}
Result:=GetWindowsEncoding;
{$ELSE}
Result:=EncodingAnsi;
{$ENDIF}
lang := GetEnv('LC_ALL');
if Length(lang) = 0 then
begin

View File

@ -53,8 +53,7 @@ interface
uses
Classes, SysUtils, LCLProc, FileUtil, StringHashList
{$IFDEF UNIX}{$IFNDEF DisableCWString}, cwstring{$ENDIF}{$ENDIF}
{$IFDEF MultiLocale},LConvEncoding{$ENDIF};
{$IFDEF UNIX}{$IFNDEF DisableCWString}, cwstring{$ENDIF}{$ENDIF};
type
{ TPOFileItem }
@ -98,28 +97,19 @@ procedure TranslateUnitResourceStrings(const ResUnitName, BaseFilename,
Lang, FallbackLang: string);
function TranslateUnitResourceStrings(const ResUnitName, AFilename: string
): boolean;
function UTF8ToSystemCharSet(const s: string): string;
{$ifndef MultiLocale} inline;{$endif}
function UTF8ToSystemCharSet(const s: string): string; inline;
implementation
function UTF8ToSystemCharSet(const s: string): string; {$ifndef MultiLocale} inline;{$endif}
function UTF8ToSystemCharSet(const s: string): string; inline;
begin
if SystemCharSetIsUTF8 then
exit(s);
{$IFDEF NoUTF8Translations}
Result:=s;
{$ELSE}
{$IFNDEF MultiLocale}
Result:=Utf8ToAnsi(s);
{$ELSE}
try
if (LowerCase(GetDefaultCodepage)<>'utf8')
and (LowerCase(GetDefaultCodepage)<>'utf-8')then
Result:=CPConvert(s,'utf8',LowerCase(GetDefaultCodepage)) else Result:=s;
except Result:=s;end;
{$ENDIF}
Result:=Utf8ToAnsi(s);
{$ENDIF}
end;