Getting the current language used on an iPhone

This forum is intended to enable people developing products using the PISD Libraries to recieve easy technical support and also to ask general questions about the libraries to other people using them.
Post Reply
User avatar
PISD Support
Moderator
Posts: 26
Joined: Thu 21 May, 2009 4:19 pm

Getting the current language used on an iPhone

Post 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.
Post Reply