uses FMX.Platform;

function GetOSLangID: String;
{$IFDEF MACOS}
var
Languages: NSArray;
begin
Languages := TNSLocale.OCClass.preferredLanguages;
Result := TNSString.Wrap(Languages.objectAtIndex(0)).UTF8String;
{$ENDIF}
{$IFDEF ANDROID}
var
LocServ: IFMXLocaleService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LocServ)) then
Result := LocServ.GetCurrentLangID;
{$ENDIF}
{$IFDEF MSWINDOWS}
var
buffer: MarshaledString;
UserLCID: LCID;
BufLen: Integer;
begin
// defaults
UserLCID := GetUserDefaultLCID;
BufLen := GetLocaleInfo(UserLCID, LOCALE_SISO639LANGNAME, nil, 0);
buffer := StrAlloc(BufLen);
if GetLocaleInfo(UserLCID, LOCALE_SISO639LANGNAME, buffer, BufLen) <> 0 then
Result := buffer
else
Result := 'en';
StrDispose(buffer);
{$ENDIF}
end;