ios - How to get the short display name from a language and region code? -
when use displaynameforkey
, language, returned string long , different native language settings in ios settings app. example:
let locale = nslocale(localeidentifier: "zh-hant") let key = nslocaleidentifier print(locale.displaynameforkey(key, value: "zh-hans")!, locale.displaynameforkey(key, value: "zh-hant-hk")!) // return 中文(簡體)and 中文(繁體,中華人民共和國香港特別行政區) // want native language settings: 簡體中文 , 繁體中文(香港)
how can short language name?
in ios10, can use localizedstring(forlanguagecode:) method of nslocale short language name.
in swift 3
let langname = nslocale.preferredlanguages[0] let locale = nslocale(localeidentifier: "zh-hant") let fullname = locale.localizedstring(forlanguagecode: lang)!
Comments
Post a Comment