I want to get the main language of a country. For example: "US" -> "en" or "VN" -> "vi" In Swift 3, are there any ways to do this?
The system has a list of common locales that include both a language and region. You can use this to get common languages for a region. There is no concept of a main language in a Locale
.
func commonLanguages(for region:String) -> [String] {
return Locale.availableIdentifiers
.map { Locale(identifier:$0) }
.filter { $0.regionCode == region }
.map { $0.languageCode ?? "??" }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With