2014-10-02 119 views
1

我從Google圖書中查找ISBN書籍。那麼我這樣做:從語言代碼獲取語言字符串

NSString *languageCode = bookInfo[@"language"];

languageCode是例如 「EN」 或 「SE」。

我想在當前語言環境中將「EN」變換爲「英語」和「SE」變爲「瑞典語」。 (所以如果當前的語言環境是瑞典語,它應該是「engelska」和「svenska」)。

我可以用蘋果Foundation做這個嗎?

回答

1

是的。

ObjC

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"]; 
[locale displayNameForKey:NSLocaleIdentifier value:@"it"]; => @"Italian" 

斯威夫特

var locale : NSLocale = NSLocale(localeIdentifier: "en") 
locale.displayNameForKey(NSLocaleIdentifier, value: "it") => Italian