2
votes

Is there a way to differentiate between traditional and simplified chinese language without delving into country codes.

Using this …

[[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]

… the language code for both is zh.

Is there a good way to query if the current language or locale is zh-HANS or zh-HANZ, without further distinction by country (zh_TW, zh_CN, etc.)?

2

2 Answers

3
votes

You can try this: used NSLocal.preferredLanguages. Get array first one, it can be zh-Hant or zh-Hants.

func getCurrentLanguage() -> String {
   let languages = NSLocale.preferredLanguages()
   let currentLanguage = languages[0] as? String
   return currentLanguage ?? ""
}
1
votes

Rewrite Zhengjie's answer in Swift 4:

func getCurrentLanguage() -> String {
    let languages = NSLocale.preferredLanguages
    let currentLanguage = languages[0]
    return currentLanguage
}