24

Simulator's language already changed to Japanese, why [[NSLocale preferredLanguages] objectAtIndex:0] always return "en"?

Neither preferred language nor region is related to "en", where does "en" come from?

Here is screenshot

Tried to get [[NSLocale preferredLanguages] objectAtIndex:2], then crash shows *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (2) beyond bounds (1)

Does it means there is no any languages are set in simulator? So weird!

This never happened before upgrading to Xcode 6.1 with iOS8.1/7.1.

Meanwhile, tried same thing on my iPhone 5, console output correct thing.

Why so weird? Does anybody have such problems?

Updates: 1

  • Delete Xcode as well as simulators, and reinstall it by downloading from Mac Store.
  • Create a new simple project, change simlulator's language
  • Still get always "en".

Oh! What's wrong....


Updates: 2

  • Today, reinstalled brand new Yosemite by reformatting HD
  • Download Xcode 6.1
  • Start a new simple default project
  • Put these codes
  • Change / Add language of simulator, Japanese, Dutch, English,
  • Run
  • Oh, God! Got only "en" again, Japanese and English not found!

Why still only one "en" could be found? Where are Japanese and English?

What happened to simulators?

Is there anything I missed?

6
  • Try setting your preferred languages for OS X (not in settings in the simulator?)
    – nielsbot
    Oct 26, 2014 at 11:36
  • Does preferred language for OS X impact that of iPhone simulator? I don't think so. Anyway, tried but not work.
    – S1U
    Oct 26, 2014 at 12:00
  • 1
    @Shoaib What's version of Xcode you're using?
    – S1U
    Oct 28, 2014 at 12:45
  • 1
    @Shoaib 6.0.1 or 6.1?
    – S1U
    Oct 28, 2014 at 19:18
  • 1
    Ver 6.0.1 but i don't think version will matter for this.
    – Shoaib
    Oct 29, 2014 at 8:03

2 Answers 2

29

This is a bug. It was driving me crazy. Apple already knows it.

See this answers:

iOS8.1 Simulator always uses US keyboard layout despite german hardware keyboard

and this:

iOS 8.1 Simulator Localization broken (NSLocalizedString)

(In the answer there is a temporary fix changing the schema)

Best, gigi

4
  • 3
    Exactly. After spending my whole day on installing/uninstalling/reinstall Xcode 5.1.1, 6.0.1, eventually found out NSLocale not work correctly was because of Xcode 6.1.
    – S1U
    Nov 1, 2014 at 2:53
  • Yep, unfortunately we have to wait Apple, or use the schema fix.
    – J.Williams
    Nov 1, 2014 at 12:20
  • PS: you should close the question:) @s1u
    – J.Williams
    Nov 1, 2014 at 12:22
  • @s1u you have to accept the best answer clicking on the check on left. This way people will immediately know what to read to have a solution or best explanation to the issue. Furthermore the question will not appear in unswared question. This will keep stackoverflow tidy and efficient
    – J.Williams
    Nov 3, 2014 at 13:08
1

My iOS simulator suddenly started reporting "en" rather than "en-US", so it seems this issue is still active.

Reproduced in:

  • Xcode 8.2.1, iOS 10
  • Xcode 9.4.1, iOS 11

I went into the language settings and English and United States were selected. I selected Canada and French, and got "fr-CA". I then switched it back and started getting "en-US" again. I've been unable to reproduce the "en" issue since.

So it appears we cannot pass the values of [NSLocale preferredLanguages] on assuming they will be Language-Region pairs.

1
  • 1
    Take a look at Settings --> General --> Language & Region --> iPhone Language, in an iOS Simulator. You will find that the Simulator is by default set to "English", not to "English (US)". That is the reason why [NSLocale preferredLanguages] reports "en" as the system language. The strangest thing is that plain "English" (without a country) seems not to be available on real devices, just on the Simulator.
    – Enrique
    Jul 10, 2020 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.