从应用程序设置更改我的 IPHONE 应用程序的语言,而不更改设备的语言
我想从应用程序设置中更改语言。为此,我制作了一个settings.bundle,并使用此代码强制使用语言如何强制 NSLocalizedString 使用特定语言,我也将 UIApplicationExitsOnSuspend 设置为 YES 以使我的应用程序每次进入后台时都会重新加载。 它对我部分有用,但我有两个问题: - 使用此方法不会改变启动屏幕(已本地化)。 - 我必须输入/返回两次才能使语言更改在应用程序视图上生效,并且仅在 OS 4 及更高版本上有效。
有人有解决办法吗?
I want to make the language changeable from the application settings. For that I made a settings.bundle and i forced the langauge using this code How to force NSLocalizedString to use a specific language , I also put the UIApplicationExitsOnSuspend to YES to make my app reload every time it goes to the background.
It partially worked for me but I have 2 problems :
- The splash screen (which is localized) is not changing with this method.
- I must enter/goBack twice to make the language change effective on the application Views an this only on the OS 4 and higher.
Has anyone a solution for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为此创建自己的翻译框架!对不起 !
You need to create you own translation framework for that ! Sorry !
不幸的是没有内置的方法。最简单的可能是集成服务,例如 GetLocalization.com,以便您的应用程序可以通过 API 下载语言文件(然后很容易添加新的语言和翻译,即使应用程序已经发布)。那么您需要的只是简单的加载程序,该加载程序将该语言文件加载到内存中,以及在运行时用翻译后的字符串替换原始字符串的函数。您可以计算原始字符串的哈希值,以便快速搜索它们,Peter Weinberger 的 hashPJW 是一个很好的算法。
Unfortunately there's no built-in way. What would be probably easiest would be integrate service like GetLocalization.com, so that your app would download language file via API (then it's easy to add new languages and translations even app is already released). Then what you need is just simple loader that loads that language file to memory and function that replaces the original string with translated one in run-time. You can calculate hash for original string so it's fast to search them, good algorithm for this is Peter Weinberger's hashPJW.
通过从应用程序中选择特定语言来使用特定语言的技巧是强制 NSLocalizedString 根据所选语言使用特定包,
这是我为此编写的文章 http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps .html
下面是一个示例应用程序的代码 https:// github.com/object2dot0/Advance-Localization-in-ios-apps
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps