iOS Localizable.strings not being retrieved from BASE file

怎甘沉沦 提交于 2019-12-18 07:18:50

问题


I am having a problem getting localization on iOS to work the way I think it is suppose to, but this is my first foray into localization so maybe I am misunderstanding.

I have three Localizable.strings files:

Base

"TAB_TITLE_Camera" = "CAMERA";

English

"TAB_TITLE_Camera" = "Camera";

Spanish

"TAB_TITLE_Camera" = "Cámara";

NSLocalizedString(@"TAB_TITLE_Camera", nil)

iOS 6.1

On Xcode 5 with a 4th generation iPod Touch running iOS 6.1, English and Spanish seem to work, but if I change to German (or any other language without a localization file) it does not pull from Base Localizable.strings, instead it pulls from the English file.

Why does it NOT pull from the BASE file?

Why DOES it pull from the English file?


iOS 7.1

Also, with a 5th generation iPod Touch running iOS 7.1, when I change to German it seems to pull from the last selected language that has a localization file, either English or Spanish. Huh?!


回答1:


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], @"");

If the current language is:

English it returns Camera

Spanish it returns Cámara

Anything else that doesn't have a localization file returns CAMERA

Simple solution that does everything I need.

Works on both iOS 6.1 and iOS 7.1.



来源:https://stackoverflow.com/questions/25680874/ios-localizable-strings-not-being-retrieved-from-base-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!