Last active
August 29, 2015 14:10
-
-
Save whiskey/ce766da2d9700ba0b4e5 to your computer and use it in GitHub Desktop.
display languages names translated by the device language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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