Search code examples
iosobjective-cios7

Get current language abbreviation (same as the localisation bundle name)


I'm trying to get the localization abbreviation for the current language.

I'm doing this:

[[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]

Using that line I can get this results: en, es, fr

the problem I have is that if my iphone is in UK-english I get the same enand not en-GB as it should be.

I also tried [NSLocale preferredLanguages] but then I get en-US for us-english or zh-Hant-US for Chinese but in this case I don't need the last part.

I'm using it because I need to manually get some resources from localisation bundles which automatically are named as follow: en.lpoj, en-GB.lpoj, zh-Hant.lproj.

Do Anybody know how could I get the current language with the same format as the localisation bundle names?


Solution

  • For anyone having the same issue you should use:

    [[NSBundle mainBundle] preferredLocalizations] 
    

    it gets the language based on what your app supports.