如何在 Objective-C 中获取可用 iPhone 语言名称的本地化列表?

发布于 2024-10-19 01:07:04 字数 695 浏览 5 评论 0原文

在 Objective-C 中,我可以轻松获取可用区域设置的列表,如下所示:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);
for (int i = 0; i < [test count]; i++) {
    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[test objectAtIndex:i]]);
}

这给了我一个如下列表:

Spanish (United States)
Macedonian (Macedonia)
Oromo (Kenya)
Danish (Denmark)
Korean (South Korea)
Tachelhit (Latin)
Fulah (Senegal)
Indonesian
Serbian (Cyrillic, Montenegro)
Makonde (Tanzania)
Welsh

然而,我想要获取的不是区域设置名称列表,而是本地化的列表语言名称,如“设置”应用程序中所示。例如,如果电话位于美国区域,我想得到“英语”,如果电话是法语,则得到“Anglais”,如果电话是德语,则得到“Englisch”。完成创建此类本地化语言名称列表的最佳方法是什么?

In Objective-C, I can easily get a list of the available Locales, like this:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);
for (int i = 0; i < [test count]; i++) {
    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[test objectAtIndex:i]]);
}

This gives me a list such as this one:

Spanish (United States)
Macedonian (Macedonia)
Oromo (Kenya)
Danish (Denmark)
Korean (South Korea)
Tachelhit (Latin)
Fulah (Senegal)
Indonesian
Serbian (Cyrillic, Montenegro)
Makonde (Tanzania)
Welsh

However, rather than a list of the Locale names, I'd like to get a localized list of language names, as in the Settings app. For example, if the phone is in the US locale, I want to get "English," if the phone is in French, "Anglais," and if in German, "Englisch." What is the best way to accomplish creating such a localized list of language names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

乜一 2024-10-26 01:07:04
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];

for (int i = 0; i < [languages count]; i++) {

    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[languages objectAtIndex:i]]);

}
NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];

for (int i = 0; i < [languages count]; i++) {

    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[languages objectAtIndex:i]]);

}
骄傲 2024-10-26 01:07:04

您也可以使用此代码:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);

for (int i = 0; i < [test count]; i++) {
    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:[test objectAtIndex:i]]);
}

它显示了更多语言。

You can use also this code:

NSArray *test = [NSLocale availableLocaleIdentifiers];
NSLog(@"%@", test);

for (int i = 0; i < [test count]; i++) {
    NSLog(@"%@", [[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:[test objectAtIndex:i]]);
}

It shows more of languages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文