Get the system language

Hi,


I have an iOS device (iPhone) set to the location in Portugal "PT" and the system language in English "EN".

When I try to know the language that is configured on iPhone


[[[NSLocale currentLocale] localeIdentifier] substringToIndex:2]


the answer is "PT" and not "EN"!

Can anyone help me how I can properly get the language that is configured in the system settings?


Thank you for your help.

JFontes

Replies

Hello,

Please use the following:

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];

I hope that helps!

Hi,


Thank you for your help.


I also have tried this and does not give the information I want, the answer is "pt_PT"


Thanks,

JFontes

>set to the location in Portugal "PT"

Did you mean 'region' (for currency/date formats, etc.)...?

If testing the language returns PT, then that is the language set on the device...sounds like you didn't really set the device to EN? Did you delete old versions being tested, option-clean the build and then test to a device configured for language EN?

Hi,


Thank you for your help.


I could not find a way to insert a photo of the screen, but the settings I have is:


- Setting - General - International

-> Language = English

-> Voice Control = English

-> Keyboards -> 3

-> Region Format = Portugal

-> Calendar = Gregorian


Thanks,

JFontes

Which iOS are you testing? I don't see the same settings you do, sorry.

Hi,


iOS 7.1.2 and 8.4, the same result 😢


Thanks,

JFontes

The "system language" is of a tricky concept. In most cases what you what is the language your app is running in, and that's available via the main bundle's

preferredLocalizations
property.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


Thank you for your help.


I want to change the language of my App, based on the iPhone's language, that's what I'm not getting, the liguagem that is selected in the iPhone settings.


Thanks,

JFontes

If you app is properly localised, the system will automatically do the right thing, that is, use the user's configured language settings to find the first localisation that's supported by your app.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


I only find pt_PT or PT, but the iPhone setting are Language = English


NSString* userLinguagem = [[[NSLocale currentLocale] localeIdentifier] substringToIndex:2];


Thanks,

JFontes

Alas, you're really off in the weeds here.

+[NSLocale currentLocale]
returns the current locale, that is, the value set by Settings > General > Language & Region > Region Formats. It has nothing to do with the language that your app is running in. It's perfectly reasonable, and in fact quite common, for users in the field to have their locale and language set to 'conflicting' values. For example, a native English speaker living in France would have the language set to English but might choose to set the locale to French (so they get metric weights and measures, 24 time, and so on).

The language that your app runs in is determined by the language setting, that is, Settings > General > Language & Region > Preferred Language Order. When the system runs your app it takes this list of languages (the preferred list) and matches it against the list of languages that your app is localised into (the app list). The first language in the preferred list that exists in the app list is the language chosen for the app. This is what you'll find in the first entry of the main bundle's

preferredLocalizations
array.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


Thank you for your help.


JFontes

Hi eskimo,


Still does not work properly!

I changed the language on iPhone (7.1.2) from English to Portuguese and continue to give "en"!


Help.

JFontes

I changed the language on iPhone (7.1.2) from English to Portuguese and continue to give "en"!

What continues to give "en"? The last post I made describes two mechanisms, so I need know which one you're actually testing.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


[[NSBundle mainBundle] preferredLocalizations]


Only gives me one object and is "en", has set the iPhone with the language in EN or PT


Thanks,

JFontes