简体   繁体   English

如何在iOS 4中更改iPhone应用程序的首选语言

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

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. 关于更改iPhone应用程序的语言的讨论很多 ,但我一直坚持这一观点:提供的解决方案要求重新启动该应用程序以使更改生效。 But how do you achieve this on an iPhone 4? 但是,如何在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. 谢谢你的帮助。

You could write your own replacement for NSLocalizedString. 您可以编写自己的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 在您的函数中,使用NSBundle加载正确的.lproj捆绑包,然后调用

[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. 我不知道这是否是最好的方法:我们必须使用它,因为我们想支持iPhone上不存在的语言,因此您的问题可能有一个更简单的解决方案。

Take a look at Apple's sample code project AppPrefs . 看一下苹果的示例代码项目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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM