Is there a platform agnostic language identifier in Delphi?
i.e. a parallel to Windows.LANG_XXX, but which can be used across all platforms?
I rant, therefore I am.
Is there a platform agnostic language identifier in Delphi?
i.e. a parallel to Windows.LANG_XXX, but which can be used across all platforms?
The closest thing I know is Firemonkey’s IFMXLocaleService, which provides GetCurrentLanguageID: string. The string returned is a two-letter string according to (one of) the ISO-639 standards.
The Windows version uses GetLocaleInfo(GetDefaultUserLCID, LOCALE_SISO639LANGNAME), or ‘en’ if that fails.
The Android version uses the first two characters of Locale.getISO3Language.
The iOS version uses the first two characters of NSLocale.currentLocale.objectForKey(NSLocaleLanguageCode).
The MacOS version uses the first two characters of NSLocale.currentLocale.localeIdentifier
Strings = garbage.
Clarification: Unusable for case statements, array indexing, etc.
Lars Fosdal I agree (though I do think that Delphi’s unability to use strings in a case statement is an obsolete limitation), but I’m afraid that’s all you’re going to get. I guess you could write your own const array of string based off http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes or http://www.loc.gov/standards/iso639-2/php/code_list.php and write your own consts to match those indexes… 🙂
Lars Fosdal You cannot do without strings, as the enum list is in flux. Reason: localization information changes too often (countries splitting themselves, countries annexing others, renaming themselves, etc).
Note that I say Language, not Locale, Jeroen Wiert Pluimers.
Translation code can be simplified with the use of a reference int, instead of a reference string.
Languages doesn’t change much, and if I need to add a new one, I’d prolly need to make code changes as I don’t do external language files.