如何在 main.h 中设置 iPhone 应用程序语言和区域覆盖设置值

发布于 2024-11-05 09:43:34 字数 699 浏览 0 评论 0原文

当您想要应用程序采用所选 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2024-11-12 09:43:34

用户默认值中有两个更有趣的键。有“AppleLanguages”和“AppleLocale”。您可以将它们设置为您喜欢的内容...:)

只需将其粘贴到代码的早期位置,您应该会得到您想要的结果...:)

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"sv"]
                                          forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"sv", @"en", nil]
                                          forKey:@"NSLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:@"sv_SE"
                                          forKey:@"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... :)

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"sv"]
                                          forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"sv", @"en", nil]
                                          forKey:@"NSLanguages"];
[[NSUserDefaults standardUserDefaults] setObject:@"sv_SE"
                                          forKey:@"AppleLocale"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文