IPhone / iOS: how can I tell you what localization the phone uses at runtime?

I have complex application localization. It must be localized in Farsi (Iranian Persian). Not only that, it should use the Solar calendar when fa_IR is selected as localization.

The OS has a Persian calendar. It is not a problem for me to use it, but I need to know that the localization fa_IR has been selected. To add insult to the injury, I cannot check this locale in the USA, as it seems that AT & T does not allow it as a localization. I have to send him to Iran, which is the royal PItA.

I have a devil of time detecting localization at runtime. There are tons of things to access the flags of the package, but I cannot find anything to get information about the runtime.

I'm very damn green in iOS programming, so I still need to determine which M is for RTFM. I searched for documents with many keywords, but to no avail.

Can anyone help with what seems like an absurdly simple question?

+6
source share
2 answers

NSLocale will have the required locale information. Note that foundation classes support proposed settings, such as 24-hour clocks and locale information.

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

The above code should help find the current localization.

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

NSLocale returns en_US , and NSBundle returns sv , which is true for my phone.

+6
source

Source: https://habr.com/ru/post/894643/


All Articles