0

I am working in localizing and app in objective-c and would like to know if there's a way to detect what is the language of the phone. More specifically, when the end user goes to Settings->General->International->Language a language is chosen so would like to know what the language has been setup for an iOS device (iPhone, iPod or iPad).

This way I can program an 'if' statement so certain code is executed in function of the language of the device.

Thank you.

Tripon
  • 81
  • 1
  • 10
  • Agustin, can you give an example of what you want to do differently based on the locale value? For example, if the locale is `en`, then you want to set the text in the UI to `Hello`, but if it's `es`, then you'd set it to `Hola`? – NSGod Apr 07 '13 at 00:13
  • (To those voting to close as a duplicate, if his answer to my question is yes, then marking this as a duplicate of either of those more general questions would be a strong disservice to him, as manually checking the locale/language and having a 15-case if/then block is **not** the way to do localization; instead, they should use the `NSLocalizedString()` macro along with `Localizable.strings` files for the appropriate .lproj folders to allow the use of a single line of code. For example, `label.text = NSLocalizedString(@"Hello", @"");`) – NSGod Apr 07 '13 at 00:17
  • Hello NSGod. What I want to do is to identify the language of the device, once this is done I want to then go over a "if" statement which will help me picking the respective variable to then display that variable in a label in the UI. Thanks. – Tripon Apr 07 '13 at 22:12

1 Answers1

2
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];

Have a look at this: Getting current device language in iOS?

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • Hi lakesh. Thanks, I ended using [[NSLocale preferredLanguages] objectAtIndex:0] in an if statement so once the language of the device has been identified I can run the code I want. – Tripon Apr 08 '13 at 01:18