12pm 12pm - 1 month ago 7
Objective-C Question

Set default localization of iOS app

I'm developing app for Russian-speaking people. A lot of countries near Russia have the second language - russian. My app has two localizations: russian and english. And I need to set russian localization like default. English should be only for people who use english like device's language.

I know that Apple recommends to use localization in priority of preferred languages in settings but I have an important reason to don't follow this recommendation.

How can I set russian localization like default?


I have not found the right solution. Only one way that is suitable for my issue is to use NSLocalizedStringFromTableInBundle instead NSLocalizedString. This way doesn't allow to localize images or nibs but with strings it works great.

Firstly you need to define the current device language:

NSString *lang = (NSString *)[[NSLocale preferredLanguages] objectAtIndex:0];

Next find the bundle for this language:

NSBundle *myLangBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"]];

If bundle is found then use it in NSLocalizedStringFromTableInBundle:

_label.text = NSLocalizedStringFromTableInBundle(@"LabelText",nil,myLangBundle,nil);

Otherwise find and use default bundle.