LCL + IDE - fixed 0014108: DefaultTranslator doesn't recognize locale on Mac OS X with help from Alexandr Grau, the supported language IDs should be added into the application bundle property list to CFBundleLocalizations key, see lazarus.app/Contents/Info.plist for example

git-svn-id: trunk@20896 -
This commit is contained in:
tombo 2009-07-19 12:20:22 +00:00
parent 58557843d3
commit b16ed5daef
6 changed files with 312 additions and 229 deletions

View File

@ -341,7 +341,7 @@ end;
initialization
LazarusTranslations:=nil;
GetLanguageIDs(SystemLanguageID1,SystemLanguageID2);
LCLGetLanguageIDs(SystemLanguageID1,SystemLanguageID2);
finalization
LazarusTranslations.Free;

View File

@ -2,132 +2,156 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>lazarus</string>
<key>CFBundleName</key>
<string>Lazarus</string>
<key>CFBundleIconFile</key>
<string>lazarus</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>laza</string>
<key>CFBundleShortVersionString</key>
<string>Lazarus IDE v0.9.25 beta</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>pas</string>
<string>pp</string>
<string>inc</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarussource</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/pascal</string>
<key>CFBundleTypeName</key>
<string>public.pascal-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpr</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusproject</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/pascal</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-project-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpi</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusproject</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/xml</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-project-info</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpk</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazaruspackage</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/xml</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-package-info</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>lfm</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusform</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/plain</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-form-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>pas</string>
<string>pp</string>
<string>inc</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarussource</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/pascal</string>
<key>CFBundleTypeName</key>
<string>public.pascal-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpr</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusproject</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/pascal</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-project-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpi</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusproject</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/xml</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-project-info</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>lpk</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazaruspackage</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/xml</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-package-info</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>lfm</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>lazarusform</string>
<key>CFBundleTypeMIMETypes</key>
<string>text/plain</string>
<key>CFBundleTypeName</key>
<string>public.lazarus-form-source</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>lazarus</string>
<key>CFBundleIconFile</key>
<string>lazarus</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
<string>es</string>
<string>af_ZA</string>
<string>ar</string>
<string>ca</string>
<string>fi</string>
<string>he</string>
<string>ja</string>
<string>fr</string>
<string>id</string>
<string>lt</string>
<string>it</string>
<string>pl</string>
<string>nl</string>
<string>pb</string>
<string>ru</string>
<string>sk</string>
<string>tr</string>
<string>ua</string>
<string>zh_CN</string>
</array>
<key>CFBundleName</key>
<string>Lazarus</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>Lazarus IDE v0.9.25 beta</string>
<key>CFBundleSignature</key>
<string>laza</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>

View File

@ -36,7 +36,7 @@ localization found.
interface
uses
Classes, SysUtils, LResources, GetText, Controls, typinfo, FileUtil
Classes, SysUtils, LResources, GetText, Controls, typinfo, FileUtil, LCLProc
{$IFDEF WINDOWS},Windows{$ENDIF};
type
@ -53,104 +53,111 @@ implementation
uses Menus;
function FindLocaleFileName:string;
var LANG,lng:string;
var
Lang, T:string;
i: Integer;
{$IFDEF WINDOWS}
Buffer:array[1..4]of char;
{$ENDIF}
function GetLocaleFileName(const LangID: String): String;
var
LangShortID: String;
begin
if LangID<>'' then
begin
//ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
Result:=ExtractFilePath(ParamStrUTF8(0))+LangID+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+LangID+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LangID+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LangID+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+
ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$IFDEF UNIX}
//In unix-like systems we can try to search for global locale
Result:='/usr/share/locale/'+LangID+'/LC_MESSAGES/'
+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$ENDIF}
//Let us search for reducted files
LangShortID:=copy(LangID,1,2);
//At first, check all was checked
Result:=ExtractFilePath(ParamStrUTF8(0))+LangShortID+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+LangShortID+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LangShortID+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LangID+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+
ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
//Full language in file name - this will be default for the project
//We need more carefull handling, as it MAY result in incorrect filename
try
Result:=ExtractFilePath(ParamStrUTF8(0))+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangID)+'.mo';
if FileExistsUTF8(Result) then exit;
//Common location (like in Lazarus)
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangID)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangID)+'.mo';
if FileExistsUTF8(Result) then exit;
except
Result:='';//Or do something else (useless)
end;
{$IFDEF UNIX}
Result:='/usr/share/locale/'+LangShortID+'/LC_MESSAGES/'
+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$ENDIF}
Result:=ExtractFilePath(ParamStrUTF8(0))+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangShortID)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangShortID)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LangShortID)+'.mo';
if FileExistsUTF8(Result) then exit;
end;
Result := '';
end;
begin
Result := '';
//Win32 user may decide to override locale with LANG variable.
LANG:=GetEnvironmentVariableUTF8('LANG');
if LANG='' then begin
Lang:=GetEnvironmentVariableUTF8('LANG');
if Lang='' then begin
for i:=1 to Paramcount-1 do
if (ParamStrUTF8(i)='--LANG') or
(ParamStrUTF8(i)='-l') or
(ParamStrUTF8(i)='--lang') then LANG:=ParamStrUTF8(i+1);
(ParamStrUTF8(i)='--lang') then Lang:=ParamStrUTF8(i+1);
end;
{$IFDEF WINDOWS}
//Modified code from lazconf.inc
if LANG='' then
begin
if GetLocaleInfo(GetUserDefaultLCID, LOCALE_SABBREVLANGNAME, @Buffer, 4)<>0 then
Lng := lowercase(copy(Buffer,1,2));
if GetLocaleInfo(GetUserDefaultLCID, LOCALE_SABBREVCTRYNAME, @Buffer, 4)<>0 then
LANG := Lng+'_'+copy(Buffer,1,2);
end;
{$ENDIF}
if Lang='' then
LCLGetLanguageIDs(Lang, T);
if LANG<>'' then begin
//ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
Result:=ExtractFilePath(ParamStrUTF8(0))+LANG+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result := GetLocaleFileName(Lang);
if Result <> '' then Exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+LANG+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LANG+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LANG+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+
ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$IFDEF UNIX}
//In unix-like systems we can try to search for global locale
Result:='/usr/share/locale/'+LANG+'/LC_MESSAGES/'
+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$ENDIF}
//Let us search for reducted files
lng:=copy(LANG,1,2);
//At first, check all was checked
Result:=ExtractFilePath(ParamStrUTF8(0))+lng+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+lng+
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+lng+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator
+LANG+DirectorySeparator+'LC_MESSAGES'+DirectorySeparator+
ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
//Full language in file name - this will be default for the project
//We need more carefull handling, as it MAY result in incorrect filename
try
Result:=ExtractFilePath(ParamStrUTF8(0))+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LANG)+'.mo';
if FileExistsUTF8(Result) then exit;
//Common location (like in Lazarus)
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LANG)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+LANG)+'.mo';
if FileExistsUTF8(Result) then exit;
except
Result:='';//Or do something else (useless)
end;
{$IFDEF UNIX}
Result:='/usr/share/locale/'+lng+'/LC_MESSAGES/'
+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
if FileExistsUTF8(Result) then exit;
{$ENDIF}
Result:=ExtractFilePath(ParamStrUTF8(0))+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+lng)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'locale'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+lng)+'.mo';
if FileExistsUTF8(Result) then exit;
Result:=ExtractFilePath(ParamStrUTF8(0))+'languages'+DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.'+lng)+'.mo';
if FileExistsUTF8(Result) then exit;
end;
Result:=ChangeFileExt(ParamStrUTF8(0),'.mo');
if FileExistsUTF8(Result) then exit;
@ -199,6 +206,7 @@ initialization
//We are to search for all
try
lcfn:=FindLocaleFileName;
DebugLn(lcfn);
except
lcfn:='';
end;

View File

@ -125,7 +125,7 @@ begin
RegisterFindGlobalComponentProc(@FindApplicationComponent);
{$ifndef wince}// remove ifdef when gettext is fixed
GetLanguageIDs(LangDefault, LangFallback);
LCLGetLanguageIDs(LangDefault, LangFallback);
if LangDefault <> '' then
FBidiMode := BidiModeMap[IsRTLLang(LangDefault)]
else

View File

@ -30,6 +30,7 @@ unit LCLProc;
interface
uses
{$IFDEF Darwin}MacOSAll, {$ENDIF}
Classes, SysUtils, Math, TypInfo, Types, FPCAdds, AvgLvlTree, FileUtil,
LCLStrConsts, LCLType, WSReferences
{$IFNDEF DisableCWString}{$ifdef unix}{$ifndef DisableIconv}, cwstring{$endif}{$endif}{$ENDIF}
@ -345,6 +346,8 @@ function ConvertUTF16ToUTF8(Dest: PChar; DestCharCount: SizeUInt;
function UTF8ToUTF16(const S: UTF8String): UTF16String;
function UTF16ToUTF8(const S: UTF16String): UTF8String;
// locale
procedure LCLGetLanguageIDs(var Lang, FallbackLang: String);
// identifier
function CreateFirstIdentifier(const Identifier: string): string;
@ -353,6 +356,8 @@ function CreateNextIdentifier(const Identifier: string): string;
implementation
uses gettext;
var
InterfaceInitializationHandlers: TFPList = nil;
@ -3376,7 +3381,7 @@ var
begin
CopyLength := Source - SourceCopied;
if CopyLength=0 then exit;
move(SourceCopied^ , Dest^, CopyLength);
System.move(SourceCopied^ , Dest^, CopyLength);
SourceCopied:=Source;
inc(Dest, CopyLength);
end;
@ -3711,7 +3716,7 @@ begin
begin
lr := Length(Result);
SetLength(Result, lr + l);
Move(cur^, Result[lr + 1], l);
System.Move(cur^, Result[lr + 1], l);
end;
inc(cur, l)
end;
@ -3798,9 +3803,9 @@ begin
if u < $10000 then
// Note: codepoints $D800 - $DFFF are reserved
Result:=widechar(u)
Result:=system.widechar(u)
else
Result:=widechar($D800+((u - $10000) shr 10))+widechar($DC00+((u - $10000) and $3ff));
Result:=system.widechar($D800+((u - $10000) shr 10))+system.widechar($DC00+((u - $10000) and $3ff));
end;
{------------------------------------------------------------------------------
@ -3846,7 +3851,7 @@ var
begin
if toUnfinishedCharToSymbol in Options then
begin
Dest[DestI] := WideChar('?');
Dest[DestI] := System.WideChar('?');
Inc(DestI);
Result := False;
end
@ -3865,7 +3870,7 @@ var
begin
if toInvalidCharToSymbol in Options then
begin
Dest[DestI] := WideChar('?');
Dest[DestI] := System.WideChar('?');
Inc(DestI);
end;
@ -3913,7 +3918,7 @@ begin
if B1 < 128 then // single byte UTF-8 char
begin
Dest[DestI] := WideChar(B1);
Dest[DestI] := System.WideChar(B1);
Inc(DestI);
end
else
@ -3929,7 +3934,7 @@ begin
begin
if (B2 and %11000000) = %10000000 then
begin
Dest[DestI] := WideChar(((B1 and %00011111) shl 6) or (B2 and %00111111));
Dest[DestI] := System.WideChar(((B1 and %00011111) shl 6) or (B2 and %00111111));
Inc(DestI);
end
else // invalid character, assume single byte UTF-8 char
@ -3951,7 +3956,7 @@ begin
W := ((B1 and %00011111) shl 12) or ((B2 and %00111111) shl 6) or (B3 and %00111111);
if (W < $D800) or (W > $DFFF) then // to single wide char UTF-16 char
begin
Dest[DestI] := WideChar(W);
Dest[DestI] := System.WideChar(W);
Inc(DestI);
end
else // invalid UTF-16 character, assume double byte UTF-8 char
@ -3975,10 +3980,10 @@ begin
C := ((B1 and %00011111) shl 18) or ((B2 and %00111111) shl 12)
or ((B3 and %00111111) shl 6) or (B4 and %00111111);
// to double wide char UTF-16 char
Dest[DestI] := WideChar($D800 or ((C - $10000) shr 10));
Dest[DestI] := System.WideChar($D800 or ((C - $10000) shr 10));
Inc(DestI);
if DestI >= DestWideCharCount then Break;
Dest[DestI] := WideChar($DC00 or ((C - $10000) and %0000001111111111));
Dest[DestI] := System.WideChar($DC00 or ((C - $10000) and %0000001111111111));
Inc(DestI);
end
else // invalid character, assume triple byte UTF-8 char
@ -4216,6 +4221,47 @@ begin
end;
end;
procedure LCLGetLanguageIDs(var Lang, FallbackLang: String);
{$IFDEF DARWIN}
function GetLanguage: String;
var
Ref: CFStringRef;
LangArray: CFMutableArrayRef;
StrSize: CFIndex;
StrRange: CFRange;
begin
Result := 'en';
LangArray := CFBundleCopyLocalizationsForPreferences(CFBundleCopyBundleLocalizations(CFBundleGetMainBundle), nil);
try
if CFArrayGetCount(LangArray) > 0 then
begin
Ref := CFArrayGetValueAtIndex(LangArray, 0);
StrRange.location := 0;
StrRange.length := CFStringGetLength(Ref);
CFStringGetBytes(Ref, StrRange, kCFStringEncodingUTF8,
Ord('?'), False, nil, 0, StrSize);
SetLength(Result, StrSize);
if StrSize > 0 then
CFStringGetBytes(Ref, StrRange, kCFStringEncodingUTF8,
Ord('?'), False, @Result[1], StrSize, StrSize);
end;
finally
CFRelease(LangArray);
end;
end;
{$ENDIF}
begin
{$IFDEF DARWIN}
Lang := GetLanguage;
FallbackLang := Copy(Lang, 1, 2);
{$ELSE}
GetLanguageIDs(Lang, FallbackLang);
{$ENDIF}
end;
function CreateFirstIdentifier(const Identifier: string): string;
// example: Ident59 becomes Ident1
var

View File

@ -36,7 +36,7 @@
uses
...
Translations, gettext;
Translations, LCLProc;
procedure TranslateLCL;
var
@ -45,7 +45,7 @@
PODirectory:='/path/to/lazarus/lcl/languages/';
Lang:='';
FallbackLang:='';
GetLanguageIDs(Lang,FallbackLang); // in unit gettext
LCLGetLanguageIDs(Lang,FallbackLang); // in unit LCLProc
Translations.TranslateUnitResourceStrings('LCLStrConsts',
PODirectory+'lclstrconsts.%s.po',Lang,FallbackLang);
end;
@ -56,6 +56,11 @@
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Note for Mac OS X:
The supported language IDs should be added into the application
bundle property list to CFBundleLocalizations key, see
lazarus.app/Contents/Info.plist for example.
}
unit Translations;