How can I get the current region from iOS settings? Not the language from settings like “en-US”, the region like “United States” or “Germany”.
Xojo.Core.Locale?
No.
Get the current locale:
Dim currentLocale As Xojo.Core.Locale
currentLocale = Xojo.Core.Locale.Current
Shows: en-US, de-DE, de-AT
This is the language, not the region.
This is the value that I want:
Your getting local Identifier which you can then use to do and query anything you like.
To get string (description) like is on Region Screen sample you can create memory table which will holds values from bellow url
http://www.loc.gov/standards/iso639-2/php/English_list.php
http://www.lingoes.net/en/translator/langcode.htm
More info about local part you can find on:
http://developer.xojo.com/xojo-core-locale
No, that is not what I want. I know the ISO639 codes and the description on developer.apple.com. On and iOS device the user can set the language for his device to German, France, Spain or any other and set the region to “Europe”, “Spain”, “Australia” or “United States” in the region settings (see picture on the first entry). This is the value that I want to check with an iOS app.
A user can set German language for the display language and set his region to “United States” .
You can identify language.
I understand what you want.
You want to have values of what is current local language and current region.
Current local language is no problem, but the region from the settings.
Guess maybe they forgot to implement that…
see regionCode | Apple Developer Documentation
The locale string such as en-US literally means “english language using US regional settings”
If a user
The locale string would be “de-US”
The locale string tells you everything you need
Okay. Thank you. Now I use this:
Dim currentLocale As Xojo.Core.Locale
currentLocale = Xojo.Core.Locale.Current
dim LanguageCode as text = currentLocale.Identifier.Right(2).Uppercase
select case LanguageCode
case “AF”
//
case “EG”
//
case “AL”
…
else
//
End Select
The first part is the language - not the last part
The last is the region
I’m not certain you can rely on “right(2)” to get the region code
I’d have to do a lot more research on how Apple has implemented locale’s to know if you can ever get any of the other allowable tags for a language tag. Some can use 2 letter OR 3 digit codes
A setting like "zh-Hant-HK should be “traditional chinese” (zh-hant) in the hong kong region (HK)
BCP 47 (see https://tools.ietf.org/html/bcp47)
Esp the part about how the lang tag is composed
Its horribly messy
You can get it like this in objective c:
NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
For iOS 10 and newer even easier:
NSString *countryCode = [[NSLocale currentLocale] countryCode];
I just can’t translate this into a Xojo Declare for you…