How to set default localization for iOS app

后端 未结 6 1033
孤城傲影
孤城傲影 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:20

    preferredLanguages sometimes return "ru_RU" but my lproj is ru.lproj. So I decided to another solutions. I added "test.lang.phrase = "YES"; to all my localizable strings files. I load a default localization if localization isn't found.

    NSString *result = nil;
    NSString *testLang = NSLocalizedString(@"test.lang.phrase", nil);
    if ([testLang isEqualToString:@"YES"]) {
        result = NSLocalizedString(str, nil);
    }
    if (!result) {
        NSBundle *myLangBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"]];
        result = NSLocalizedStringFromTableInBundle(str, nil, myLangBundle,nil);
    }
    

提交回复
热议问题