开发者

iPhone/iOS: How Do I Tell What Localization The Phone is Using At Runtime?

开发者 https://www.devze.com 2023-03-27 07:54 出处:网络
I\'m having a difficult time localizing an app. It needs to be localized into Farsi (Iranian Persian). Not only that, it needs to use the Solar Calendar, when fa_IR is selected as a localization.

I'm having a difficult time localizing an app. It needs to be localized into Farsi (Iranian Persian). Not only that, it needs to use the Solar Calendar, when fa_IR is selected as a localization.

The OS has a Persian calendar. It's no problem for me to use it, but I need to know that the fa_IR localization has been selected. To add insult to injury, I can't test this locale in the US, as it seems that AT&T doesn't allow it as a localization. I have to send it to Iran, which is a royal PItA.

I'm having the devil of a time finding out the localization at runtime. There's a bunch of stuff for accessing the bundle flags, but I can't find anything for getting runtime info.

I'm pretty damn green at iOS programming, so I still need to determine which M to RTFM. I've been sear开发者_StackOverflow社区ching the docs with many keywords, to no avail.

Can anyone help with what seems to be an absurdly easy question?


NSLocale will have the locale information you need. Do note that foundation classes support suggested settings such as 24 hour clock and locale information.

NSLog(@"%@", [[NSLocale currentLocale] localeIdentifier]);


NSArray *localizations = [[NSBundle mainBundle] preferredLocalizations];
for (NSString *string in localizations) {
    NSLog(@"Localization: %@", string);
}

The above code should be helpful in finding the current localization.

NSLog(@"%@", [[NSLocale currentLocale] localeIdentifier]);

NSLocale returns en_US, while NSBundle returns sv, which is correct for my phone.

0

精彩评论

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