0

I'm trying to write tests for a piece of code I wrote that converts dates to en_US_POSIX using an NSDateFormatter. The tests seem to launch an iOS simulator when running, and changing the language here seems to also change the language used when running a test.

Is there a way I can programmatically set the emulator's language so that a particular test (or test suite) will be in the proper language I want to test with?

[UPDATE] I've tried using the "-AppleLanguages" and "-AppleLocales" parameters for my scheme, but neither seem to affect the language during test runs - [[NSLocale currentLocale] localeIdentifier] still returns en_US, and [NSDate date] still outputs as a normal yyyy-MM-dd HH:mm:ss ZZZ format.

[UPDATE] I don't believe this is a duplicate. The article cites changing the language in Settings not having any effect, but I can do this in my simulator and see the keyboard language change in my App. The issue revolves around a simple call to [NSDate date] always returning the date in an en_UTC-style format, regardless of using a language with a non-Roman character set, like Arabic.


[Solved] I've found the solution. Apparently, the output of functions like [NSDate date] is determined by the system LOCALE, not the language. Removing the -AppleLanguages argument and replacing it with -AppleLocale ar_AE caused the output of [NSDate date] to appear in Arabic, which is what I'm looking for.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Argus9
  • 1,863
  • 4
  • 26
  • 40
  • How did you format the argument for -AppleLanguages? `-AppleLanguages (es)` ? – Mike Welsh Feb 11 '15 at 23:47
  • I've tried using the short form (ar) as well as full names, like (Arabic). In both cases, [NSLocale preferredLanguages] objectAtIndex:0] returns "ar" so it would seem it accepts both formats. – Argus9 Feb 12 '15 at 14:48

1 Answers1

1

Which Xcode version do you use? If you are using Xcode6.1(or 6.1.1), the simulator has a bug. please see iOS8.1 Simulator always uses US keyboard layout despite german hardware keyboard

Community
  • 1
  • 1
kmugitani
  • 615
  • 1
  • 6
  • 13
  • I'm not 100% sure this is the same issue - I can go into the simulator's Settings > General > Language settings and set a language there, like Arabic, and the keyboard will actually change in my app. The issue is that this value doesn't seem to affect the format of the outputted NSDate. It's always in an en_UTC-type format. – Argus9 Feb 12 '15 at 14:50
  • This problem is fixed at latest iOS8.2beta or iOS8.3beta simulator. So you can try same thing with the latest iOS8.2beta simulator. – kmugitani Feb 13 '15 at 00:49