ZetaPR
ZetaPR

Reputation: 993

NSLocale preferredLanguages is retrieving always 'en' language

I'm trying to get the correct language in my device (is NOT in the SIMULATOR) with the following code:

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

And it is always 'en' but my current language is set to Spanish

Any thoughts why is retrieving always 'en' and not the current device language?

Upvotes: 5

Views: 1435

Answers (2)

Ramakrishna
Ramakrishna

Reputation: 752

I've to face the same issue. In my case, it was solved by setting the Application Language as System Language in Edit Scheme.

Here is the way:

Edit Scheme -> Options -> Application language -> System Language.

Upvotes: 6

ZetaPR
ZetaPR

Reputation: 993

After a few research, I found out that the key AppleLanguages was being overwritten. So, the

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults objectForKey:@"AppleLanguages"];

It was returning a dictionary list with the overwritten data. I just did this:

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSDictionary * dict = [defaults dictionaryRepresentation];
for (id key in dict) {
    if([key isEqualToString:@"AppleLanguages"]){
        [defaults removeObjectForKey:key];
    }
}
[defaults synchronize];

In order to delete the whole key and the system reset it and return the correct list.

Upvotes: 1

Related Questions