【问题标题】:Objective C : how to get the list of possible values returned by [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]?Objective C:如何获取 [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode] 返回的可能值列表?
【发布时间】:2013-07-29 14:46:30
【问题描述】:

我用:

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

确定用户语言。

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

谢谢!

【问题讨论】:

  • 查找ISO-3166
  • 谢谢,但它是国家列表,而不是语言列表。例如,该方法将为巴西人返回“pt”,而不是“br”。

标签: ios macos localization internationalization


【解决方案1】:

有两种方法可供选择。

  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 上使用吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 2017-03-06
  • 1970-01-01
  • 2021-04-30
相关资源
最近更新 更多