如何在 main.h 中设置 iPhone 应用程序语言和区域覆盖设置值
当您想要应用程序采用所选 iPhone 设置值以外的语言/地区/格式时。具有自己的内部语言设置的应用程序示例。
我知道如何更改语言,但是区域/格式怎么办?
要轻松覆盖设置中选定的语言,您可以在 main 中运行此代码
[[NSUserDefaults standardUserDefaults]
setObject:[NSArray arrayWithObject:@"sv"]
forKey:@"AppleLanguages"];
要查看效果的更改,让我们使用以下代码输出当前设置
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
NSLog(@"current locale: %@", locale);
NSArray* preferredLangs = [NSLocale preferredLanguages];
NSLog(@"preferredLangs: %@", preferredLangs);
输出为
current locale: en_US
preferredLangs: ( sv )
但我想将此语言环境更改为 sv_SE
我怎样才能在相同的情况下如何覆盖 iPhone 设置中的区域设置(区域/格式)?
In a case when you want a App in a language/region/format other than selected iPhone settings value. Example a App with it's own internal language settings.
I know how to change the language, but what about the region/format?
To easily override the selected language in settings you can run this code in main
[[NSUserDefaults standardUserDefaults]
setObject:[NSArray arrayWithObject:@"sv"]
forKey:@"AppleLanguages"];
To view the change in effect, let us output current settings with below code
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
NSLog(@"current locale: %@", locale);
NSArray* preferredLangs = [NSLocale preferredLanguages];
NSLog(@"preferredLangs: %@", preferredLangs);
With the output coming as
current locale: en_US
preferredLangs: ( sv )
But I want to change this locale to sv_SE
How can i in the same way override the locale(Region/Format) in the iPhone Settings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户默认值中有两个更有趣的键。有“AppleLanguages”和“AppleLocale”。您可以将它们设置为您喜欢的内容...:)
只需将其粘贴到代码的早期位置,您应该会得到您想要的结果...:)
there are two more interesting key in the user defaults. Theres 'AppleLanguages' and 'AppleLocale'. You can set them to your hearts content... :)
Just paste this somewhere early in your code, and you should get the results you're after... :)