How to Localize the Images in Images.Xcassets

How to localize the images in Images.xcassets?

If you are using an Asset Catalog:

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.)

If you need to determine localized images at run time without using the Asset Catalog:

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

Localization of Image Assets in Xcode 10

To localize Assets in Assets.xcassets is apparently currently not possible, since the Xcode file inspector does not show a localization option.

However, it is possible to localise the name of the image file that you want to load, using something like

let img = UIImage.init(named: NSLocalizedString("LOCALIZATION_KEYWORD", comment:""))  

see here (in Obj-c)

Localization of buttons with images

Are you loading the image from a Storyboard or programmatically?

If programmatically, then you can localise the string of the file name and have different images for each localisation.

change pictures of ImageView by localization

You can do it like this by using the NSLocalizedString, so you declare you array like this:

let help0 = UIImage(named: NSLocalizedString("help0", comment: ""))
let help1 = UIImage(named: NSLocalizedString("help1", comment: ""))
let help2 = UIImage(named: NSLocalizedString("help2", comment: ""))
let help3 = UIImage(named: NSLocalizedString("help3", comment: ""))
let help4 = UIImage(named: NSLocalizedString("help4", comment: ""))

let imageArray = [help0, help1, help2, help3, help4]

Then you add your localization langiages in your example ENG and GER and in those files you add the image you want to use, like this (a guide of how to add localization):

Localization for English:
"help0" = "help0Eng";
"help1" = "help1Eng";
etc...

Localization for German:
"help0" = "help0Ger";
"help1" = "help1Ger";
etc...

And your help0Eng, help0Ger etc. is the name of the images in your Assets.xcassets. So the following will happen:

  1. NSLocalizedString("help0", comment: "") will be localzied in the right file for the selected language
  2. That image name will be used for help0

Localizable xcassets files?

I've also looked for this, and after some time looking around it seems that is not possible for the moment using the xcassets, although it may change in the future... or not

Apple currently recommends that the launch image should simulate the app first screen but without content.

Apple launch images guidelines



Related Topics



Leave a reply



Submit