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:
- NSLocalizedString("help0", comment: "") will be localzied in the right file for the selected language
- 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
After Switching to Xcode 7, App Size Grew from 9 Mb to 60 Mb, Is There a Fix
Refresh Uipageviewcontroller - Reorder Pages and Add New Pages
iOS Video Compression Swift iOS 8 Corrupt Video File
Checking a Null Value in Objective-C That Has Been Returned from a JSON String
How Is the Relation Between Uiview's Clipstobounds and Calayer's Maskstobounds
Uibutton Doesn't Listen to Content Mode Setting
Uicollectionview Adding Uicollectioncell
Swift: How to Get Substring from Start to Last Index of Character
What Tool(S) How to Use to Produce iPhone App Screencasts
Make Custom Button on Tab Bar Rounded
Simulator Slow-Motion Animations Are Now On
Building iOS Applications Using Xcodebuild Without Codesign
iPhone - When to Calculate Heightforrowatindexpath for a Tableview When Each Cell Height Is Dynamic
Get Current iPhone Device Timezone Date and Time from Utc-5 Timezone Date and Time iPhone App