Note that there are some explanatory texts on larger screens.

plurals
  1. PONSLocale currentLocale always returns "en_US" not user's current language
    primarykey
    data
    text
    <p>I'm in the processes of internationalizing an iPhone app - I need to make programmatic changes to certain views based on what the user's current locale is. I'm going nuts because no matter what the language preference on the iPhone simulator or actual hardware are, <code>locale</code> always evaluates to "en_US":</p> <pre><code>NSString *locale = [[NSLocale currentLocale] localeIdentifier]; NSLog(@"current locale: %@", locale); </code></pre> <p>The crazy thing is that the rest of the application behaves as expected. The correct strings are selected from the Localization.strings file and used in the interface, and the correct .xib files for the selected locale are used.</p> <p>I have also tried the following, to no avail and with the same result:</p> <pre><code>NSString *locale = [[NSLocale autoupdatingCurrentLocale] localeIdentifier]; NSLog(@"current locale: %@", locale); </code></pre> <p>Is there something simple I'm missing? A preference or an import perhaps?</p> <p><strong>What I used to do:</strong></p> <p>As Darren's answer suggests, the preference I'm looking for is not in <code>NSLocale</code>, rather it is here:</p> <pre><code>NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; NSArray* languages = [userDefaults objectForKey:@"AppleLanguages"]; NSString* preferredLanguage = [languages objectAtIndex:0]; NSLog(@"preferredLanguage: %@", preferredLang); </code></pre> <p><strong>Peter's answer seems to be a better solution:</strong></p> <pre><code>NSArray* preferredLanguages = [NSLocale preferredLanguages]; NSLog(@"preferredLanguages: %@", preferredLanguages); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload