iOS:管理本地化图像 [英] iOS : Manage Localized Images

查看:76
本文介绍了iOS:管理本地化图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2套适用于iPhone App的本地化图像.我应该如何放置图像?以及如何加载到应用程序中?

I have 2 sets of localized images for iPhone App. How should I place the images ? And how can I load into the app?

文件夹结构如下:

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)

我该如何解决?

推荐答案

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

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

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

And in the Localizable.strings file just map that image name like so (assuming that japanese is your default language):

@"myimage_jp" = @"myimage_cn"

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

Of course you would have to have 2 versions of the image in the resources (myimage_jp and myimage_cn)

这篇关于iOS:管理本地化图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆