Getting the current language used on an iPhone
Posted: Thu 17 Dec, 2009 2:04 am
The iPhone lacks a simple 'get language' implementation BUT it is fairly easy to persuade it to give up the current language which the phone is operating in using the code snippet listed below:
This will return one of Apples language abbreviations, I'll be honest I don't know all of them but they're fairly easy to work out in the main:
So just do a string compare with the returned string to determine the actual language which is set.
Code: Select all
const CHAR* get_iphone_language_setting( void )
{
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
return [preferredLang UTF8String];
}
Code: Select all
en = English
fr = French
es = Spanish