Created
April 21, 2017 18:00
-
-
Save gservera/3b6d1024b1cdde47ca46b421f3966d82 to your computer and use it in GitHub Desktop.
A Swift 3 snippet to list every Locale identifier on Apple platforms. Just run it on a playground and there it is.
This file contains 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
// | |
// LocaleIdentifiers.swift | |
// Xcode Playgrounds | |
// | |
// Created: Guillem Servera Negre on 21/04/2017. | |
// Copyright: Public domain. | |
// | |
import Foundation | |
let myLocaleIdentifier = "ca" // ← Set yours here 😉 | |
let sortedLocaleIdentifiers = Locale.availableIdentifiers.sorted {$0 < $1} | |
let sourceLocale = NSLocale(localeIdentifier: myLocaleIdentifier) | |
sortedLocaleIdentifiers.forEach { | |
let name = sourceLocale.localizedString(forLocaleIdentifier: $0) | |
let identifierLength = $0.characters.count | |
var glue: String | |
switch $0.characters.count { | |
case 0...3: glue = "\t\t\t\t" | |
case 4...7: glue = "\t\t\t" | |
default: glue = "\t\t" | |
} | |
print("\($0),\(glue)\(name)") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code above should print a list similar to this one: