Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization does not work anymore under iOS 9 / iOS 9.0.1

Since I create iOS Apps I use the following code to translate / localize my apps:

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([language isEqualToString:@"de"]) {
    // localized language
}
else { //base language
}

But since the update to iOS 9 this code does not work anymore. All my apps are now in English.

Neither the apps I already have in the app store, nor the apps I run in the Simulator are localized anymore.

It would be great if you could tell me how I have to translate my code programmatically in iOS 9.

like image 472
EANicolas1 Avatar asked Nov 10 '22 04:11

EANicolas1


1 Answers

I could solve the problem.

If I use the following code the localization works under iOS 9.

[[NSBundle mainBundle] preferredLocalizations];
NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
        if ([language isEqualToString:@"de"]){
            // localization
        }
        else {
            //base language
        }

I hope that will help some of you, too.

like image 190
EANicolas1 Avatar answered Dec 05 '22 13:12

EANicolas1