AppleLanguages value overrides the value of language set in IOS settings preferred language

我们两清 提交于 2019-11-28 06:51:49

问题


I am working on Localization of my app that supports both spanish and English languages.These options are listed in a tableview.On clicking English i am setting the value "en" for the key "AppleLanguages" in NSUserDefaults.So that it can show the content in English.

NSUserDefaults *nsdefault=[NSUserDefaults standardUserDefaults];
            [nsdefault setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
            [nsdefault synchronize];

Also at the same time i am trying to fetch the Language programmatically from IOS device which was set at General>>International>>Language manually using code.

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

For the very first time language gives me correct value that has been set.But If i change my option from list like Spanish or English and set value for key "AppleLanguages".It overrides the value of my device setting language.And from then ownwards i dont get the correct value of language under Setting>>International>>Language.

I want that every time i choose the language manually in settings like Francis etc.I should be able to get the newly set language.I even tried to follow the link by apple.

https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpinternational/Articles/ChoosingLocalizations.html

Any help would be appreciated.


回答1:


There is not a right way to do that and you should not do that.
You should only rely on the system settings. I gave you one reason for not doing that: all system calls are made with system language. If you force one language such as spanish in an english system and you display a map inside your app you will see all streets etc in english, the same happen if you request reverse geocoding or other system services.



来源:https://stackoverflow.com/questions/19497047/applelanguages-value-overrides-the-value-of-language-set-in-ios-settings-preferr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!