How to retrieve the current User Locale

- by

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:

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:

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.