iOS Localizable.strings not being retrieved from BASE file
Asked Answered
F

1

1

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

Footstall answered 5/9, 2014 at 7:40 Comment(1)
Maybe I can use NSLocalizedStringFromTable to select the base file. I'll look into that.Footstall
F
2

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.

Footstall answered 19/9, 2014 at 6:6 Comment(1)
what about just some key absent?Switchback

© 2022 - 2024 — McMap. All rights reserved.