Is there the official way to set fallback localize

2019-09-09 04:03发布

In iOS app development, I could't find the official way to set fallback localized language. I want to use English when user language is not included in my app's localizations. I tried way to use Base Internationalisation, however, all doesn't work for all language. Now, replace base.lproj to en.lproj, only languages added into my app are work well, but other languages are doesn't work well. (English not used, instead Korean is used when select a Russian...)

Some sites say that, set fallback language with value of "Localisation native development region", However, it didn't work well. Do you have any idea? Thanks.

1条回答
老娘就宠你
2楼-- · 2019-09-09 04:43

Your problem sounds pretty much like the problem I was having. Spent a lot of time looking for a solution until I finally came up with this approach (my issue link and text below).

iOS Localizable.strings not being retrieved from BASE file


Found a way to determine whether or not I have a localization file for the currently selected language, and if not, I can pull from the Base localization file.

NSString *path = [[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"];
if (path == nil)
{
    path = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"lproj"];
}

NSLocalizedStringFromTableInBundle(@"TAB_TITLE_Camera", @"Localizable", [NSBundle bundleWithPath:path], @"");

Simple solution that does everything I need.

Works on both iOS 6.1 and iOS 7.1.


If you don't have a localization file for the currently selected language, or you want to specify a particular language, just set the value for pathForResource and you should get the language you want.

查看更多
登录 后发表回答