ios - objective-c : how to get the list of possible values returned by [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]?

标签 ios macos localization internationalization

我用:

NSString *language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];

确定用户语言。

我在哪里可以获得可能的返回值(例如“fr”)和相应语言(例如“french”)的完整列表。

谢谢!

最佳答案

有 2 种方式可供选择。

  1. 遍历 Locale.isoLanguageCodes 并提取所有 2 字母代码:
    for languageCode in Locale.isoLanguageCodes {
        print(languageCode) // or print(languageCode.prefix(2))
    }
  1. 遍历 Locale.availableIdentifiers 并对每个项目执行 Locale.components(fromIdentifier:_)
for identifier in Locale.availableIdentifiers {
    let components = Locale.components(fromIdentifier: identifier)
    // ...
 }

完整列表在 ISO-639-1 中标准化列表。

关于ios - objective-c : how to get the list of possible values returned by [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17927067/

相关文章:

c++ - MAC 操作系统 : dynamically linked library not found despite correct rpath

macos - 在 mac el capitan 上将公式降级到以前的版本 (opencv3/3.0.0)

c - 尝试删除单词的第一个字符并将其放在末尾

ios - ipad怎么知道键盘被隐藏了

ios - 以编程方式将 UILabel 字体设置为用户定义的运行时属性

c++ - XCode 自动停用断点

ios - JSQMessagesViewController 更改发送按钮 TextView 占位符的语言

asp.net - 测试本地化网站

ios - 如何在 ios swift 中显示来自 url 的图像

iOS 团队配置。 Xcode 不提供我们的团队配置文件作为选项。为什么?