How to change the preferred language of an iPhone app in iOS 4

那年仲夏 提交于 2019-12-19 10:15:12

问题


Changing the language of an iPhone app has been discussed many times, but I'm stuck with this one: The provided solutions require the app to be restarted to make the changes take effect. But how do you achieve this on an iPhone 4? Pressing "home" sends the app to the background and clicking the app icon just brings it back. The user has experience as if the app had been restarted and wonders why the language hasn't changed. Thanks for your help.


回答1:


You could write your own replacement for NSLocalizedString. In the header file, do something like

#undef NSLocalizedString
#define NSLocalizedString(key, comment) MyLocalizedStringFunction(key)

In your function, load the correct .lproj bundle using NSBundle, then call

[bundle localizedStringForKey:key value:nil table:nil];

on it to get the string you want.

I don't know if that's the best way: we had to use it because we wanted to support a language that didn't exist on the iPhone, so your problem may have a simpler solution.




回答2:


Take a look at Apple's sample code project AppPrefs. It shows how to handle changes made in the Settings app when bringing your app back to the foreground. The sample code handles settings specific to the app, but could also be used for 'system-wide' setting changes. Hope this helps.



来源:https://stackoverflow.com/questions/3235671/how-to-change-the-preferred-language-of-an-iphone-app-in-ios-4

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