user2091150
user2091150

Reputation: 998

How to get locale id in iOS/Android

I need to get the locale id like the one returned by Windows:

GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, PChar(locale), 256)

for iOS and Android. I need that for SQL Server collation info (LCID).

Upvotes: 2

Views: 1242

Answers (2)

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28551

Your function GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, PChar(locale), 256) will return Windows specific LCID code number.

For instance for US English it will return 0409 hex code, where 09 marks primary language ID (en) and 04 is sort order identifier. Windows Locale Identifiers Format

Problem is that you cannot get such number on other platforms, and you would have to create custom lookout tables to map platform locale (you can find platform locale using @RRUZ answer) to Windows one.

The best you can get is on OS X, where you can get primary Windows Locale ID with following code:

uses
  Macapi.Foundation;

var
  WinID: integer;

   WinID := TNSLocale.OCClass.windowsLocaleCodeFromLocaleIdentifier(TNSLocale.Wrap(TNSLocale.OCClass.currentLocale).localeIdentifier);

In case of US English above function will return 0009 hex code.

Upvotes: 2

RRUZ
RRUZ

Reputation: 136451

You can access to the device locale service use the TPlatformServices and the IFMXLocaleService interface.

uses
  FMX.Platform;
...
...
var
  LService: IFMXLocaleService;
  LangID  : string;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LService)) then
    LangID := LService.GetCurrentLangID;
end;

Upvotes: 6

Related Questions