Skip to content

Instantly share code, notes, and snippets.

@whiskey
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save whiskey/ce766da2d9700ba0b4e5 to your computer and use it in GitHub Desktop.

Select an option

Save whiskey/ce766da2d9700ba0b4e5 to your computer and use it in GitHub Desktop.
display languages names translated by the device language
// Playground - noun: a place where people can play
import Foundation
// an example list of device languages
let deviceLocales = ["DE", "GB", "SE", "no_NB", "DA", "FR", "PL", "MK"]
// this comes from the APIs city list
let countryCodes = ["DE", "GB", "US", "SE", "DK", "JP"]
func simpler() {
for locale in deviceLocales {
// simulate a device locale of code 'langCode'
let deviceLocale = NSLocale.localeWithLocaleIdentifier(locale)
// show all countries in the device language
for code in countryCodes {
//println(code)
let country = deviceLocale.displayNameForKey(NSLocaleCountryCode, value: code)
println("[device: \(locale)] \(country!)")
}
println()
}
}
simpler()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment