如何在 Objective-C 中获取可用 iPhone 语言名称的本地化列表?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以使用此代码:
它显示了更多语言。
You can use also this code:
It shows more of languages.