我用:
NSString *language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
确定用户语言。
我在哪里可以获得可能的返回值(例如“fr”)和相应语言(例如“french”)的完整列表。
谢谢!
最佳答案
有 2 种方式可供选择。
- 遍历
Locale.isoLanguageCodes
并提取所有 2 字母代码:
for languageCode in Locale.isoLanguageCodes {
print(languageCode) // or print(languageCode.prefix(2))
}
- 遍历
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/