LazUtils: Remove special macOS handling from LazGetLanguageIDs procedure. Handle macOS just as any Unix.

For the record, the logic of this code was the following:
1. If the App Bundle does not do any Locale configuration, 'English' is
returned (i. e. not an ISO code).
2. If the App Bundle has configured the Locale configuration that
matches the user's system settings, it will return locale name from its
list, e. g. 'zh_CN'.
3. If the App Bundle cannot match the Locale of the user system, the
first item set in the App Bundle is returned (`en` in case of Lazarus).

So this code provided no tangible benefits and introduced dependency on
language list in Lazarus bundle. This list was outdated and thus
prevented autodetection of Czech, Hungarian, Brazilian Portuguese,
Ukrainian languages on macOS.

In case there will a need to reintroduce special macOS handling arise,
NSLocale.object() should be called with `countryCode` and `languageCode`
keys.
This commit is contained in:
Maxim Ganetsky 2023-06-11 20:02:50 +03:00
parent 5e66a6fc46
commit 97c198b599

View File

@ -217,9 +217,7 @@ var
implementation
uses
gettext
{$IFDEF Darwin}, MacOSAll{$ENDIF}
;
gettext;
{$IFDEF WinCE}
// CP_UTF8 is missing in the windows unit of the Windows CE RTL
@ -4020,58 +4018,10 @@ begin
end;
procedure LazGetLanguageIDs(var Lang, FallbackLang: String);
{$IFDEF DARWIN}
function GetLanguage: boolean;
var
Ref: CFStringRef;
LangArray: CFMutableArrayRef;
StrSize: CFIndex;
StrRange: CFRange;
Locals: CFArrayRef;
Bundle: CFBundleRef;
begin
Result := false;
Bundle:=CFBundleGetMainBundle;
if Bundle=nil then exit;
Locals:=CFBundleCopyBundleLocalizations(Bundle);
if Locals=nil then exit;
LangArray := CFBundleCopyLocalizationsForPreferences(Locals, nil);
try
if CFArrayGetCount(LangArray) > 0 then
begin
Ref := CFArrayGetValueAtIndex(LangArray, 0);
StrRange.location := 0;
StrRange.length := CFStringGetLength(Ref);
StrSize:=0;
CFStringGetBytes(Ref, StrRange, kCFStringEncodingUTF8,
Ord('?'), False, nil, 0, StrSize);
SetLength(Lang, StrSize);
if StrSize > 0 then
begin
CFStringGetBytes(Ref, StrRange, kCFStringEncodingUTF8,
Ord('?'), False, @Lang[1], StrSize, StrSize);
Result:=true;
FallbackLang := Copy(Lang, 1, 2);
end;
end;
finally
CFRelease(LangArray);
CFRelease(Locals);
end;
end;
{$ENDIF}
var
p: SizeInt;
begin
{$IFDEF DARWIN}
if not GetLanguage then
GetLanguageIDs(Lang, FallbackLang);
{$ELSE}
GetLanguageIDs(Lang, FallbackLang);
{$ENDIF}
//Language ID e. g. on Linux can be in a form of `ru_RU.utf8`, which will prevent
//loading files with name in a form of `project1.ru_RU.po`.
//Trim this trailing encoding.