Page 1 of 1

Getting the current language used on an iPhone

Posted: Thu 17 Dec, 2009 2:04 am
by PISD Support
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:

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];
}
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:

Code: Select all

en = English
fr = French
es = Spanish
So just do a string compare with the returned string to determine the actual language which is set.