Reputation: 54212
I have 2 sets of localized images for iPhone App. How should I place the images ? And how can I load into the app?
The folder structure is as follow:
For English version:
/MyApp/en.lproj/Localizable.strings , InfoPList.strings
/MyApp/en.lproj/*.png (images)
For Traditional Chinese version:
/MyApp/zh-Hant.lproj/Localizable.strings , InfoPList.strings
/MyApp/Resources/*.png (images)
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *locale = [[defaults objectForKey:@"AppleLanguages"] objectAtIndex:0];
NSString* path= [[NSBundle mainBundle] pathForResource:locale ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
SomeViewController *vc = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:languageBundle];
I would like to use the same filename for both set of images and make it autoload. Is it possible?
Now I encounter a problem. In the debug console, it said:
NSBundle </Users/SomeUser/Library/Application Support/iPhone Simulator/5.0/Applications/1DC22505-1E78-4B5E-A794-DBF72DC786AE/MyApp.app/zh-Hant.lproj> (not yet loaded)
How can I solve it ?
Upvotes: 3
Views: 4681
Reputation:
Why do you get the language bundle yourself? You could just localize the image file name like so:
NSString *imageName = NSLocalizedString(@"myimage_jp", @"localized image");
UIImage *image = [UIImage imageNamed:imageName];
And in the Localizable.strings
file just map that image name like so (assuming that japanese is your default language):
@"myimage_jp" = @"myimage_cn"
Of course you would have to have 2 versions of the image in the resources (myimage_jp
and myimage_cn
)
Upvotes: 7