开发者

iPhone Localization - Get the phone's language code?

开发者 https://www.devze.com 2022-12-16 01:08 出处:网络
I\'m localizing my iPhone app for multiple languages, and in a开发者_如何学编程ddition to changing some of the strings I need to change some backgrounds.Is it possible to query the iPhone and get the

I'm localizing my iPhone app for multiple languages, and in a开发者_如何学编程ddition to changing some of the strings I need to change some backgrounds. Is it possible to query the iPhone and get the user's language code?

Thanks!


Take a look at NSLocale:

NSString   *language = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
NSString   *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];


solved my own question!

NSString *language = [[NSLocale preferredLanguages] firstObject];
if (!language) {
   language = @"en";
}
NSLog(@"The device's specified language is %@", language);

Swift version :

var language : String! = "en"
if let lng = NSLocale.preferredLanguages().first {
  language = lng
}
print("The device's specified language is \(language)")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号