I have a rather complicated project, consisting of several large localized subprojects.
Most of my subprojects are localized through a single Localizable.strings file. This file is copied to the SubProjectName.bundle target, which is used with the SubProjectName.a static library in the main project. It works great.
However, one of my subprojects contains many localized .strings files. This project cannot read lines in any language other than English, regardless of how the device (or simulator) is configured.
For example, this line of code always returns the English line:
[[NSBundle myResourcesBundle] localizedStringForKey:@"MY_TEST_STRING" value:@"" table:@"MyTable"]
Where MyTable corresponds to the MyTable.strings file localized in several languages. When I look at the .app package, all localizations are there, sitting inside the "MyBundle.bundle" resource in the application.
The following code, however, correctly finds translations for a given string in all localizations:
for (NSString *language in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) { NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle myResourcesBundle] pathForResource:language ofType:@"lproj"]]; NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"MY_TEST_STRING", @"MyTable", bundle, nil)); }
So, when the package is the actual folder MyBundle.bundle/<LanguageCode>.lproj , string search works. But obviously, this defeats the goal of the automatic search provided by iOS.
(Note that the [NSBundle myResourcesBundle] above is just a static convenience method for retrieving my custom package for a subproject).
-
Change I have already experimented with this, and if I delete the en.lproj folder from my subproject package, it correctly uses the device or simulator locale.
For example, I have:
MyApp.app/ | - MyResources.bundle/ | - en.lproj/ | - zh-Hans.lproj/
When I install the simulator (or device) on Chinese Simplified, it searches for strings in en.lproj , although the language standard is zh-Hans . If I delete the en.lproj folder and restart the application, it correctly uses zh-Hans localization.