Get Device Language and Region Code

May 24, 2017 - 1 minute read -
ios swift

From time to time I need to send Language ISO (or something like this) to a server as a parameter. Here is a little function which can handle this:

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