iOS:管理本地化图像

时间:2012-02-22 06:44:23

标签: objective-c ios5

我为iPhone App提供了2套本地化图像。我应该如何放置图像?我怎样才能加载到应用程序中?

文件夹结构如下:

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];

我想对两组图像使用相同的文件名并使其自动加载。有可能吗?

现在我遇到了一个问题。在调试控制台中,它说:

NSBundle </Users/SomeUser/Library/Application Support/iPhone Simulator/5.0/Applications/1DC22505-1E78-4B5E-A794-DBF72DC786AE/MyApp.app/zh-Hant.lproj> (not yet loaded)

我该如何解决?

1 个答案:

答案 0 :(得分:7)

为什么你自己获得语言包?您可以像这样本地化图像文件名:

NSString *imageName = NSLocalizedString(@"myimage_jp", @"localized image");
UIImage *image = [UIImage imageNamed:imageName];

Localizable.strings文件中只映射该图像名称(假设日语是您的默认语言):

@"myimage_jp" = @"myimage_cn"

当然,您必须在资源中拥有2个版本的图片(myimage_jpmyimage_cn

相关问题