mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-21 04:03:00 +02:00
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:
parent
58557843d3
commit
b16ed5daef
@ -341,7 +341,7 @@ end;
|
|||||||
|
|
||||||
initialization
|
initialization
|
||||||
LazarusTranslations:=nil;
|
LazarusTranslations:=nil;
|
||||||
GetLanguageIDs(SystemLanguageID1,SystemLanguageID2);
|
LCLGetLanguageIDs(SystemLanguageID1,SystemLanguageID2);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
LazarusTranslations.Free;
|
LazarusTranslations.Free;
|
||||||
|
@ -2,132 +2,156 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>English</string>
|
<string>English</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleDocumentTypes</key>
|
||||||
<string>lazarus</string>
|
<array>
|
||||||
<key>CFBundleName</key>
|
<dict>
|
||||||
<string>Lazarus</string>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<key>CFBundleIconFile</key>
|
<array>
|
||||||
<string>lazarus</string>
|
<string>*</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
</array>
|
||||||
<string>6.0</string>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<key>CFBundlePackageType</key>
|
<array>
|
||||||
<string>APPL</string>
|
<string>****</string>
|
||||||
<key>CFBundleSignature</key>
|
</array>
|
||||||
<string>laza</string>
|
<key>CFBundleTypeRole</key>
|
||||||
<key>CFBundleShortVersionString</key>
|
<string>Editor</string>
|
||||||
<string>Lazarus IDE v0.9.25 beta</string>
|
</dict>
|
||||||
<key>CFBundleVersion</key>
|
<dict>
|
||||||
<string>1</string>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<key>CSResourcesFileMapped</key>
|
<array>
|
||||||
<true/>
|
<string>pas</string>
|
||||||
<key>CFBundleDocumentTypes</key>
|
<string>pp</string>
|
||||||
<array>
|
<string>inc</string>
|
||||||
<dict>
|
</array>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeIconFile</key>
|
||||||
<string>Editor</string>
|
<string>lazarussource</string>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
<array>
|
<string>text/pascal</string>
|
||||||
<string>*</string>
|
<key>CFBundleTypeName</key>
|
||||||
</array>
|
<string>public.pascal-source</string>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>****</string>
|
<string>****</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
<key>CFBundleTypeRole</key>
|
||||||
<dict>
|
<string>Editor</string>
|
||||||
<key>CFBundleTypeRole</key>
|
</dict>
|
||||||
<string>Editor</string>
|
<dict>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<array>
|
<array>
|
||||||
<string>pas</string>
|
<string>lpr</string>
|
||||||
<string>pp</string>
|
</array>
|
||||||
<string>inc</string>
|
<key>CFBundleTypeIconFile</key>
|
||||||
</array>
|
<string>lazarusproject</string>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
<string>lazarussource</string>
|
<string>text/pascal</string>
|
||||||
<key>CFBundleTypeMIMETypes</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string>text/pascal</string>
|
<string>public.lazarus-project-source</string>
|
||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<string>public.pascal-source</string>
|
<array>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<string>****</string>
|
||||||
<array>
|
</array>
|
||||||
<string>****</string>
|
<key>CFBundleTypeRole</key>
|
||||||
</array>
|
<string>Editor</string>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<string>Editor</string>
|
<array>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<string>lpi</string>
|
||||||
<array>
|
</array>
|
||||||
<string>lpr</string>
|
<key>CFBundleTypeIconFile</key>
|
||||||
</array>
|
<string>lazarusproject</string>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
<string>lazarusproject</string>
|
<string>text/xml</string>
|
||||||
<key>CFBundleTypeMIMETypes</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string>text/pascal</string>
|
<string>public.lazarus-project-info</string>
|
||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<string>public.lazarus-project-source</string>
|
<array>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<string>****</string>
|
||||||
<array>
|
</array>
|
||||||
<string>****</string>
|
<key>CFBundleTypeRole</key>
|
||||||
</array>
|
<string>Editor</string>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<string>Editor</string>
|
<array>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<string>lpk</string>
|
||||||
<array>
|
</array>
|
||||||
<string>lpi</string>
|
<key>CFBundleTypeIconFile</key>
|
||||||
</array>
|
<string>lazaruspackage</string>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
<string>lazarusproject</string>
|
<string>text/xml</string>
|
||||||
<key>CFBundleTypeMIMETypes</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string>text/xml</string>
|
<string>public.lazarus-package-info</string>
|
||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<string>public.lazarus-project-info</string>
|
<array>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<string>****</string>
|
||||||
<array>
|
</array>
|
||||||
<string>****</string>
|
<key>CFBundleTypeRole</key>
|
||||||
</array>
|
<string>Editor</string>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<string>Editor</string>
|
<array>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<string>lfm</string>
|
||||||
<array>
|
</array>
|
||||||
<string>lpk</string>
|
<key>CFBundleTypeIconFile</key>
|
||||||
</array>
|
<string>lazarusform</string>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
<string>lazaruspackage</string>
|
<string>text/plain</string>
|
||||||
<key>CFBundleTypeMIMETypes</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string>text/xml</string>
|
<string>public.lazarus-form-source</string>
|
||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeOSTypes</key>
|
||||||
<string>public.lazarus-package-info</string>
|
<array>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<string>****</string>
|
||||||
<array>
|
</array>
|
||||||
<string>****</string>
|
<key>CFBundleTypeRole</key>
|
||||||
</array>
|
<string>Editor</string>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
</array>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>Editor</string>
|
<string>lazarus</string>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<key>CFBundleIconFile</key>
|
||||||
<array>
|
<string>lazarus</string>
|
||||||
<string>lfm</string>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
</array>
|
<string>6.0</string>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleLocalizations</key>
|
||||||
<string>lazarusform</string>
|
<array>
|
||||||
<key>CFBundleTypeMIMETypes</key>
|
<string>en</string>
|
||||||
<string>text/plain</string>
|
<string>de</string>
|
||||||
<key>CFBundleTypeName</key>
|
<string>es</string>
|
||||||
<string>public.lazarus-form-source</string>
|
<string>af_ZA</string>
|
||||||
<key>CFBundleTypeOSTypes</key>
|
<string>ar</string>
|
||||||
<array>
|
<string>ca</string>
|
||||||
<string>****</string>
|
<string>fi</string>
|
||||||
</array>
|
<string>he</string>
|
||||||
</dict>
|
<string>ja</string>
|
||||||
</array>
|
<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>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -36,7 +36,7 @@ localization found.
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LResources, GetText, Controls, typinfo, FileUtil
|
Classes, SysUtils, LResources, GetText, Controls, typinfo, FileUtil, LCLProc
|
||||||
{$IFDEF WINDOWS},Windows{$ENDIF};
|
{$IFDEF WINDOWS},Windows{$ENDIF};
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -53,104 +53,111 @@ implementation
|
|||||||
uses Menus;
|
uses Menus;
|
||||||
|
|
||||||
function FindLocaleFileName:string;
|
function FindLocaleFileName:string;
|
||||||
var LANG,lng:string;
|
var
|
||||||
|
Lang, T:string;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
{$IFDEF WINDOWS}
|
{$IFDEF WINDOWS}
|
||||||
Buffer:array[1..4]of char;
|
Buffer:array[1..4]of char;
|
||||||
{$ENDIF}
|
{$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
|
begin
|
||||||
|
Result := '';
|
||||||
//Win32 user may decide to override locale with LANG variable.
|
//Win32 user may decide to override locale with LANG variable.
|
||||||
LANG:=GetEnvironmentVariableUTF8('LANG');
|
Lang:=GetEnvironmentVariableUTF8('LANG');
|
||||||
if LANG='' then begin
|
if Lang='' then begin
|
||||||
for i:=1 to Paramcount-1 do
|
for i:=1 to Paramcount-1 do
|
||||||
if (ParamStrUTF8(i)='--LANG') or
|
if (ParamStrUTF8(i)='--LANG') or
|
||||||
(ParamStrUTF8(i)='-l') or
|
(ParamStrUTF8(i)='-l') or
|
||||||
(ParamStrUTF8(i)='--lang') then LANG:=ParamStrUTF8(i+1);
|
(ParamStrUTF8(i)='--lang') then Lang:=ParamStrUTF8(i+1);
|
||||||
end;
|
end;
|
||||||
{$IFDEF WINDOWS}
|
if Lang='' then
|
||||||
//Modified code from lazconf.inc
|
LCLGetLanguageIDs(Lang, T);
|
||||||
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 begin
|
Result := GetLocaleFileName(Lang);
|
||||||
//ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
|
if Result <> '' then Exit;
|
||||||
Result:=ExtractFilePath(ParamStrUTF8(0))+LANG+
|
|
||||||
DirectorySeparator+ChangeFileExt(ExtractFileName(ParamStrUTF8(0)),'.mo');
|
|
||||||
if FileExistsUTF8(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');
|
Result:=ChangeFileExt(ParamStrUTF8(0),'.mo');
|
||||||
if FileExistsUTF8(Result) then exit;
|
if FileExistsUTF8(Result) then exit;
|
||||||
|
|
||||||
@ -199,6 +206,7 @@ initialization
|
|||||||
//We are to search for all
|
//We are to search for all
|
||||||
try
|
try
|
||||||
lcfn:=FindLocaleFileName;
|
lcfn:=FindLocaleFileName;
|
||||||
|
DebugLn(lcfn);
|
||||||
except
|
except
|
||||||
lcfn:='';
|
lcfn:='';
|
||||||
end;
|
end;
|
||||||
|
@ -125,7 +125,7 @@ begin
|
|||||||
RegisterFindGlobalComponentProc(@FindApplicationComponent);
|
RegisterFindGlobalComponentProc(@FindApplicationComponent);
|
||||||
|
|
||||||
{$ifndef wince}// remove ifdef when gettext is fixed
|
{$ifndef wince}// remove ifdef when gettext is fixed
|
||||||
GetLanguageIDs(LangDefault, LangFallback);
|
LCLGetLanguageIDs(LangDefault, LangFallback);
|
||||||
if LangDefault <> '' then
|
if LangDefault <> '' then
|
||||||
FBidiMode := BidiModeMap[IsRTLLang(LangDefault)]
|
FBidiMode := BidiModeMap[IsRTLLang(LangDefault)]
|
||||||
else
|
else
|
||||||
|
@ -30,6 +30,7 @@ unit LCLProc;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
{$IFDEF Darwin}MacOSAll, {$ENDIF}
|
||||||
Classes, SysUtils, Math, TypInfo, Types, FPCAdds, AvgLvlTree, FileUtil,
|
Classes, SysUtils, Math, TypInfo, Types, FPCAdds, AvgLvlTree, FileUtil,
|
||||||
LCLStrConsts, LCLType, WSReferences
|
LCLStrConsts, LCLType, WSReferences
|
||||||
{$IFNDEF DisableCWString}{$ifdef unix}{$ifndef DisableIconv}, cwstring{$endif}{$endif}{$ENDIF}
|
{$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 UTF8ToUTF16(const S: UTF8String): UTF16String;
|
||||||
function UTF16ToUTF8(const S: UTF16String): UTF8String;
|
function UTF16ToUTF8(const S: UTF16String): UTF8String;
|
||||||
|
|
||||||
|
// locale
|
||||||
|
procedure LCLGetLanguageIDs(var Lang, FallbackLang: String);
|
||||||
|
|
||||||
// identifier
|
// identifier
|
||||||
function CreateFirstIdentifier(const Identifier: string): string;
|
function CreateFirstIdentifier(const Identifier: string): string;
|
||||||
@ -353,6 +356,8 @@ function CreateNextIdentifier(const Identifier: string): string;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses gettext;
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
InterfaceInitializationHandlers: TFPList = nil;
|
InterfaceInitializationHandlers: TFPList = nil;
|
||||||
@ -3376,7 +3381,7 @@ var
|
|||||||
begin
|
begin
|
||||||
CopyLength := Source - SourceCopied;
|
CopyLength := Source - SourceCopied;
|
||||||
if CopyLength=0 then exit;
|
if CopyLength=0 then exit;
|
||||||
move(SourceCopied^ , Dest^, CopyLength);
|
System.move(SourceCopied^ , Dest^, CopyLength);
|
||||||
SourceCopied:=Source;
|
SourceCopied:=Source;
|
||||||
inc(Dest, CopyLength);
|
inc(Dest, CopyLength);
|
||||||
end;
|
end;
|
||||||
@ -3711,7 +3716,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
lr := Length(Result);
|
lr := Length(Result);
|
||||||
SetLength(Result, lr + l);
|
SetLength(Result, lr + l);
|
||||||
Move(cur^, Result[lr + 1], l);
|
System.Move(cur^, Result[lr + 1], l);
|
||||||
end;
|
end;
|
||||||
inc(cur, l)
|
inc(cur, l)
|
||||||
end;
|
end;
|
||||||
@ -3798,9 +3803,9 @@ begin
|
|||||||
|
|
||||||
if u < $10000 then
|
if u < $10000 then
|
||||||
// Note: codepoints $D800 - $DFFF are reserved
|
// Note: codepoints $D800 - $DFFF are reserved
|
||||||
Result:=widechar(u)
|
Result:=system.widechar(u)
|
||||||
else
|
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;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -3846,7 +3851,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if toUnfinishedCharToSymbol in Options then
|
if toUnfinishedCharToSymbol in Options then
|
||||||
begin
|
begin
|
||||||
Dest[DestI] := WideChar('?');
|
Dest[DestI] := System.WideChar('?');
|
||||||
Inc(DestI);
|
Inc(DestI);
|
||||||
Result := False;
|
Result := False;
|
||||||
end
|
end
|
||||||
@ -3865,7 +3870,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if toInvalidCharToSymbol in Options then
|
if toInvalidCharToSymbol in Options then
|
||||||
begin
|
begin
|
||||||
Dest[DestI] := WideChar('?');
|
Dest[DestI] := System.WideChar('?');
|
||||||
Inc(DestI);
|
Inc(DestI);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3913,7 +3918,7 @@ begin
|
|||||||
|
|
||||||
if B1 < 128 then // single byte UTF-8 char
|
if B1 < 128 then // single byte UTF-8 char
|
||||||
begin
|
begin
|
||||||
Dest[DestI] := WideChar(B1);
|
Dest[DestI] := System.WideChar(B1);
|
||||||
Inc(DestI);
|
Inc(DestI);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -3929,7 +3934,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if (B2 and %11000000) = %10000000 then
|
if (B2 and %11000000) = %10000000 then
|
||||||
begin
|
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);
|
Inc(DestI);
|
||||||
end
|
end
|
||||||
else // invalid character, assume single byte UTF-8 char
|
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);
|
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
|
if (W < $D800) or (W > $DFFF) then // to single wide char UTF-16 char
|
||||||
begin
|
begin
|
||||||
Dest[DestI] := WideChar(W);
|
Dest[DestI] := System.WideChar(W);
|
||||||
Inc(DestI);
|
Inc(DestI);
|
||||||
end
|
end
|
||||||
else // invalid UTF-16 character, assume double byte UTF-8 char
|
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)
|
C := ((B1 and %00011111) shl 18) or ((B2 and %00111111) shl 12)
|
||||||
or ((B3 and %00111111) shl 6) or (B4 and %00111111);
|
or ((B3 and %00111111) shl 6) or (B4 and %00111111);
|
||||||
// to double wide char UTF-16 char
|
// 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);
|
Inc(DestI);
|
||||||
if DestI >= DestWideCharCount then Break;
|
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);
|
Inc(DestI);
|
||||||
end
|
end
|
||||||
else // invalid character, assume triple byte UTF-8 char
|
else // invalid character, assume triple byte UTF-8 char
|
||||||
@ -4216,6 +4221,47 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function CreateFirstIdentifier(const Identifier: string): string;
|
||||||
// example: Ident59 becomes Ident1
|
// example: Ident59 becomes Ident1
|
||||||
var
|
var
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
...
|
...
|
||||||
Translations, gettext;
|
Translations, LCLProc;
|
||||||
|
|
||||||
procedure TranslateLCL;
|
procedure TranslateLCL;
|
||||||
var
|
var
|
||||||
@ -45,7 +45,7 @@
|
|||||||
PODirectory:='/path/to/lazarus/lcl/languages/';
|
PODirectory:='/path/to/lazarus/lcl/languages/';
|
||||||
Lang:='';
|
Lang:='';
|
||||||
FallbackLang:='';
|
FallbackLang:='';
|
||||||
GetLanguageIDs(Lang,FallbackLang); // in unit gettext
|
LCLGetLanguageIDs(Lang,FallbackLang); // in unit LCLProc
|
||||||
Translations.TranslateUnitResourceStrings('LCLStrConsts',
|
Translations.TranslateUnitResourceStrings('LCLStrConsts',
|
||||||
PODirectory+'lclstrconsts.%s.po',Lang,FallbackLang);
|
PODirectory+'lclstrconsts.%s.po',Lang,FallbackLang);
|
||||||
end;
|
end;
|
||||||
@ -56,6 +56,11 @@
|
|||||||
Application.CreateForm(TForm1, Form1);
|
Application.CreateForm(TForm1, Form1);
|
||||||
Application.Run;
|
Application.Run;
|
||||||
end.
|
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;
|
unit Translations;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user