[Programming] Detecting the current device language


I know, anyone can see what is the current language he/she is using in his/her mobile. But I am discussing here how can we access this information from an application. I googled around and came across couple of alternatives to get this information. I still don’t know which one is the better solution but still here are those. 😉

NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@”AppleLanguages”];
NSString* preferredLang = [languages objectAtIndex:0];
NSLog(@”preferredLang: %@”, preferredLang);

Another alternative is:

NSArray* languages = [NSLocale preferredLanguages];
NSString* preferredLang = [languages objectAtIndex:0];
NSLog(@”preferredLang:%@”,preferredLang);

In both cases, you will get a language code of current preferred language of your device. As one can see, we have an array of language codes and technically the first one in the array is the preferred one. But here I thought for a second, that what does these codes represent so I googled again a lot of times and finally found which language code represents which language. The language codes used are following the standard coding convention proposed by ISO 639 (ref: Wikipedia). The list which I got from the arrays above is as follow:

  • en………………….english
  • fr…………………..french
  • de………………….german
  • ja…………………..japanese
  • nl…………………..dutch
  • it……………………italian
  • es…………………..spanish
  • pt…………………..portuguese (Brazil)
  • pt-PT………………portuguese (Portugal)
  • da………………….danish
  • fi……………………finnish
  • nb………………….norwegian
  • sv ………………….swedish
  • ko ………………….korean
  • zh-Hans ………….chinese simplified
  • zh-Hant …………..chinese traditional
  • ru……………………russian
  • pl……………………polish
  • tr……………………turkish
  • uk…………………..ukrainian
  • ar……………………arabic
  • hr…………………..croatian
  • cs…………………..czech
  • el……………………greek
  • he…………………..hebrew
  • ro…………………..romanian/Moldavian
  • sk…………………..slovak
  • th…………………..thai
  • id…………………..indonesian
  • ms………………….malay
Happy language accessing 😉
Advertisements