如何本地化 Images.xcassets 中的图像? [英] How to localize the images in Images.xcassets?

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

问题描述

我们可以像这样使用 Localize...File Inspector 中本地化图像:

We can localize an image in the File Inspector using Localize... like this:

那么我们可以得到这个:

Then we can get this:

但是现在,我在 iOS 项目中使用 Images.xcassets 来管理我的图像,我应该如何在 Images.xcassets 中本地化这些图像?

But now, I use Images.xcassets to manage my images in my iOS project, how should I localize these images in Images.xcassets?

推荐答案

如果您使用的是资产目录:

资产目录元素现在可以本地化.在资产的信息面板中,有一个本地化"部分列出了您在项目设置中为项目设置的所有语言.如果您不选择其中任何一个,您的图像将被视为通用"(即,它们将采用默认行为).如果您选择其中一个或多个,您将能够为通用"和任何替代语言选择不同的图像.

Asset catalog elements are now localizable. In the information panel for an asset, there is a "Localization" section that lists all the languages you've set up for your project in the project settings. If you don't select any of them, your images will be deemed "universal" (i.e., they will adopt the default behavior). If you select one or more of them, you will be able to select different images for "universal" and any alternate language.

例如,如果您的基本语言是英语,并且您想要西班牙语替代语言,请仅选择西班牙语"并将替代版本拖入西班牙语井中,并将英语版本保留为通用.然后,在运行时,如果选择的语言是西班牙语,那么西班牙语图像将被拉出.否则,它将拉取英文版本.(或者,如果您想要与其他所有"都不同的特定英语和西班牙语版本,也请选中英语并拖入相应的英语和通用图像.)

For example, if your base language is English, and you want Spanish-language alternates, select only "Spanish" and drag in the alternate versions in the Spanish wells, and leave the English versions as the Universal. Then, at run-time, if the chosen language is Spanish, then the Spanish-language image will be pulled. Otherwise, it will pull the English version. (Or, if you want specific English and Spanish versions that are both different from "everything else", also check English and drag in the corresponding English and Universal images.)

如果您需要在运行时确定本地化图像而不使用资产目录:

虽然目前有 (显然)不是 直接显式本地化 xcassets 文件的方法,但您可以改为使用 Localizable.strings 文件本地化要提取的资产名称.例如,假设您对需要本地化的游戏主菜单进行了图形徽标处理.您可以将本地化徽标处理放在具有不同名称的资产文件中,将名称添加到 Localizable.strings 文件中,然后使用如下代码获取适当的图像:

While there's (apparently) not currently a way to explicitly localize the xcassets file directly, you could instead localize the name of the asset to pull using your Localizable.strings file. For instance, say you have a graphic logo treatment for the main menu of a game that needs to be localized. You could put the localized logo treatments in the assets file with different names, add the names to your Localizable.strings file, and then fetch the appropriate image with code like this:

UIImage *img = [UIImage imageNamed:NSLocalizedString(@"MAIN_MENU_IMAGE", nil)];

这篇关于如何本地化 Images.xcassets 中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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