更改当前 iphone 应用程序的区域设置(NSBundle 的自定义区域设置?)
我想在我的 iphone 应用程序中以编程方式更改区域设置(基本上是因为 iphone 本身并不支持所有语言,所以用户应该可以仅为我的应用程序切换语言)。我在另一个问题上看到如何强制 NSLocalizedString 使用OSX 应用程序上的特定语言?它应该与 [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; 一起使用- 但对我来说,这并不... [NSLocale currentLocale] 仍然返回系统范围的区域设置,并且“主包”为我提供来自系统范围区域设置的文件..
那么.. 有没有办法为我的应用程序设置自定义区域设置?或者 - 这对我来说就足够了 - 创建一个具有不同语言环境的新 NSBundle 实例?
i want to change the locale programmatically in my iphone app (basically because not all languages are supported by iphone itself, it should be possible for the user to switch language only for my application). I have seen on a different question How to force NSLocalizedString to use a specific language that on OSX apps? it should work with [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; - but for me it doesn't...
[NSLocale currentLocale] still returns the system wide locale and the 'main bundle' gives me files from the system wide locale..
so.. is there a way to set a custom locale for my application? or - which would be sufficient for me - create a new NSBundle instance with a different locale?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,愚蠢的我..因为链接的问题已经回答了..该代码需要重新启动..即。当用户选择另一种语言时,调用 [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; - 下次启动应用程序时,[NSBundle mainBundle] 将返回给定区域设置的正确资源..(尽管 [NSLocale currentLocale] 仍将返回 iphone 范围的区域设置..但我认为这对我来说并不重要反正...)
ok, stupid me.. as the question linked already answered.. that code requires a restart.. ie. when the user selects another language call [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; - the next time the application is launched the [NSBundle mainBundle] will return the correct resources for the given locale.. (although [NSLocale currentLocale] will still return the iphone-wide locale.. but i think this doesn't matter to me anyway...)