Skip to content

Instantly share code, notes, and snippets.

@yossan
Last active September 12, 2015 07:53
Show Gist options
  • Save yossan/dcb32f2cf20bbc69da9f to your computer and use it in GitHub Desktop.
Save yossan/dcb32f2cf20bbc69da9f to your computer and use it in GitHub Desktop.
import Foundation
/*
NSLocaleについて
# 特徴
設定できるのが最初の言語と国が指定できるlocaleIdentifierのみ。
出力オンリー。
言語ごとに、文字名を出力させることが出来る。
ex 言語を日本語に設定すると以下の出力は日本語になり、
英語にすると英語で出力される。
print(locale.displayNameForKey(NSLocaleScriptCode, value:"Latn"))
print(locale.displayNameForKey(NSLocaleScriptCode, value:"Hira"))
print(locale.displayNameForKey(NSLocaleScriptCode, value:"Kana"))
print(locale.displayNameForKey(NSLocaleScriptCode, value:"Hang"))
国ごとに各固有の値を取得することが出来る。
* 使用通貨
* 使用言語
* クォーテーションマーク
*/
extension NSLocale {
func detailDescription() {
let idt = self.objectForKey(NSLocaleIdentifier)
let countryCode = self.objectForKey(NSLocaleCountryCode)
let language = self.objectForKey(NSLocaleLanguageCode)
let currencyCode = self.objectForKey(NSLocaleCurrencyCode)
let currencySymbole = self.objectForKey(NSLocaleCurrencySymbol)
let calendar = self.objectForKey(NSLocaleCalendar)
if let _ = idt {
print("identifier = \(idt!)")
}
else {
print("Unknown locale")
}
if let _ = countryCode {
print("Country Code = \(countryCode!)")
}
else {
print("No Country")
}
if let _ = language {
print("Using language = \(language!)")
}
if let _ = calendar {
print("Using calendar = \(calendar!.calendarIdentifier)")
}
if let _ = currencyCode, let _ = currencySymbole {
print("Currency Code = \(currencyCode!)")
print("Currncy Symbole = \(currencySymbole!)")
}
}
}
let locale = NSLocale(localeIdentifier:"JP")
locale.detailDescription()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment