Getting current device language in iOS?

前端 未结 30 2350
星月不相逢
星月不相逢 2020-11-22 09:10

I\'d like to show the current language that the device UI is using. What code would I use?

I want this as an NSString in fully spelled out format. (Not

30条回答
  •  -上瘾入骨i
    2020-11-22 09:44

    Simple Swift 3 function:

      @discardableResult
      func getLanguageISO() -> String {
        let locale = Locale.current
        guard let languageCode = locale.languageCode,
              let regionCode = locale.regionCode else {
            return "de_DE"
        }
        return languageCode + "_" + regionCode
      }
    

提交回复
热议问题