【发布时间】:2015-06-26 16:15:58
【问题描述】:
我需要像 Windows 返回的那样获取区域设置 ID:
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, PChar(locale), 256)
适用于 iOS 和 Android。我需要它用于 SQL Server 排序信息 (LCID)。
【问题讨论】:
我需要像 Windows 返回的那样获取区域设置 ID:
GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, PChar(locale), 256)
适用于 iOS 和 Android。我需要它用于 SQL Server 排序信息 (LCID)。
【问题讨论】:
您可以使用TPlatformServices 和IFMXLocaleService 接口访问设备区域设置服务。
uses
FMX.Platform;
...
...
var
LService: IFMXLocaleService;
LangID : string;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LService)) then
LangID := LService.GetCurrentLangID;
end;
【讨论】:
您的函数GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, PChar(locale), 256) 将返回Windows specific LCID code number。
例如,对于美国英语,它将返回 0409 十六进制代码,其中 09 标记主要语言 ID (en),04 是排序顺序标识符。 Windows Locale Identifiers Format
问题是您无法在其他平台上获得这样的数字,并且您必须创建自定义查找表以将平台区域设置(您可以使用 @RRUZ 答案找到平台区域设置)映射到 Windows 平台。
您可以在 OS X 上获得最好的结果,您可以使用以下代码获取主要的 Windows 区域设置 ID:
uses
Macapi.Foundation;
var
WinID: integer;
WinID := TNSLocale.OCClass.windowsLocaleCodeFromLocaleIdentifier(TNSLocale.Wrap(TNSLocale.OCClass.currentLocale).localeIdentifier);
如果是美国英语,上述函数将返回 0009 十六进制代码。
【讨论】: