Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

ios7 - iOS Localizable.strings not being retrieved from BASE file

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?!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...