开发者

how to track language changes in iPad?

I'm new in developing iOS app. So I've recently faced a problem with localization of my app. I would like to perform some actions in response to language change in system settings. To get language ID I use

[[NSLocale preferredLanguages] objectAtIndex:0];

in applicationDidFinishLaunchingWithOptions method. First time it returns language ID right (e.g. "en" for English). Then, I close my application (or send it to background) and change language to German. Aft开发者_如何转开发er that I restart my app, but instead of "de", it still returns "en". I think my app might probably store old settings somewhere... but where exactly? How to retrieve valid current value?


take a look at this old answer:

Getting current device language in iOS?

EDIT:

NSString *testLang = [[NSLocale preferredLanguages] objectAtIndex:0];
NSString *testLang1 = [[NSLocale preferredLanguages] objectAtIndex:1];
NSString *testLang2 = [[NSLocale preferredLanguages] objectAtIndex:2];
NSString *testLang3 = [[NSLocale preferredLanguages] objectAtIndex:3];
NSString *testLang4 = [[NSLocale preferredLanguages] objectAtIndex:4];
NSLog(@"LINGUA SYS:%@:%@:%@:%@:%@",testLang,testLang1,testLang2,testLang3,testLang4);

in debugger console:

LINGUA SYS:en:it:fr:de:ja

or:

LINGUA SYS:es:en:it:fr:de

or:

LINGUA SYS:pt-PT:en:es:it:fr

so the code you posted is right, the error should be somewhere else...


if you do something like that:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en",@"es", nil] forKey:@"AppleLanguages"];

the value is stored on NSUSerDefaults and changes on settings don't apply.


I found the source of my problem. It was iOS Simulator. I installed my app on device and all problems disappeared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜