How to set default localization for iOS app

后端 未结 6 1029
孤城傲影
孤城傲影 2021-02-07 01:51

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

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 02:15

    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.

提交回复
热议问题