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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -