How to retrieve the current User Locale

The following method will return a two letter code of which language is set on the iOS device in question:

NSString *myLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];

There’s a list of language codes on Wikipedia: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Note that to compare the current value against a list of languages you support we need use the isEqualToString method. Here’s an example:

    NSString *myLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];

    if ([myLanguage  isEqualToString:@"de"]) {
        self.myLabel.text = @"Deutsch";
    } else if ([myLanguage isEqualToString:@"en"]) {
        self.myLabel.text = @"English";
    } else {
        self.myLabel.text = @"didn't work";
    }

The following articles have helped me figure this out:





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.