1

This is the code I am using (Taken from - Converting Country Codes to Country Names)

  NSLocale *locale = [NSLocale currentLocale];
  NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
  NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
  NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];

On device with english I'll get this: "Argentina"

But, on device with other language i'll get something like: "\U05d0\U05e8\U05d2\U05e0\U05d8\U05d9\U05e0\U05d4"

Any idea?

Community
  • 1
  • 1
Yossi
  • 2,525
  • 2
  • 21
  • 24
  • Did you set the local language of the device (or simulator) to Hebrew? – Hermann Klecker Apr 10 '14 at 11:01
  • That iOS 7 string happens to be "ארגנטינה" (unicode formatted). Are you sure that the two are using the same locale and language? – David Rönnqvist Apr 10 '14 at 11:04
  • I see... It nothing to do with the OS version, but the definitions on the device... so how can I find the english name if the device is with other language ? – Yossi Apr 10 '14 at 11:07

1 Answers1

4

It is Hebrew and means something like argntynhe or argntynhe or so. (Unfortunately I do not speak any Hebrew. Just converted the unicode to something meaningful.)

Check the language settings of your device or the locale identifier that you used to initialize your locale with.

Try this.

NSLocale myLocale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
NSString *country = [myLocale displayNameForKey: NSLocaleIdentifier value: identifier];

I am just not positive about the constant @"en_US"; I took that out of the top of my head. Just google for an appropriate value.

Further docs: https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSLocale_Class/Reference/Reference.html

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71