I have a button with image.How can I localize it, in order it to have another image on different language ?
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.
If your image is not in an xcassets you can localize it in the file inspector.
If you image is in an xcassets, you can include the language identifier in its name, or as #jdapps said, localize the image name in a strings file.
You can add localized names for your images to Localizable.strings file and use "NSLocalizedString(key: String, comment: String)" method to access it. Works great for me.
Select the “image” in the project navigator. Next, bring up the file inspector, and locate the localization section, in which you’ll see a button named “Localize…”. Click the button and you’ll be prompted for confirmation. Choose English and click the “Localize” button to confirm.
Switch back to the finder and local the project directory. You’ll find two folders: en.lproj and Base.lproj. Both folders are automatically generated by Xcode for localization. The en.lproj folder stores resource files for English localization,If you localise for french language too, then fr.lproj folder will be added and is for French localization. If you look into both folders, each one contains the image file. Download the French version of the cover image from here (or use whatever image you like). Copy the cover image just downloaded and replace the one in fr.lproj folder.
Related
I am using localisation in my project and also having localisation files for storyboard. But when I am doing some changes in storyboard the new controls strings are not reflecting in the .strings files. I need to manually copy paste the controls code and set localisation string for each. So is there any other way to update localisation strings file for storyboard. By adding script in build phase or anything like that...
This will remove any translations you already had in your strings file (so save them somewhere before doing this), but it might be easier to just paste translations back in, then to add storyboard objects by id.
Select your storyboard file.
In the File inspector on right, uncheck strings file you want to regenerate.
Check it again and it will be regenerated with new UI elements.
I don't use storyboard or xib for this project (full code)
When I add new localization, it shows no file in the list, and when I press Finish, no folder created.
You need a Localizable.strings file. If you already have that, select the file in the left panel. Then, click the button that should be in the right panel that says "Localize..."
Once you do this, you should be able to add other localizations the way you were trying to.
I know how to localize storyboard elements like label, buttons etc. However, I faced a problem where I need to localize the images that were setup in a storyboard in the attribute inspector for the Image View.
Is there a way to localize those without setting those images up in the code, in the viewDidLoad method and calling setImage:[UIImage imageNamed: NSLocalizedString(...)]; ?
Any kind of help is highly appreciated!
I guess I figured it out...maybe not the ideal way of doing it but works for me...
Open image folder in your Project Navigator (panel).
When you click one of the images, on the right (Inspector panel) you'll see the button "Localize".
Clicking on that button gives you a pop-up asking if you want it to be the base (in my case I say yes).
So now in the inspector there're check boxes: Base, language 1, language 2 etc (language n - is the languages you added to your project in the localization settings).
So now if you put a check mark into one of the language check boxes, your image file will have a drop down arrow showing that it has some content inside. If you click that, you'll see how it expands showing the localized files with the name of the language in the () brackets.
However, at this point those files are all the same as the base. So now you need to substitute the base files with the localized ones.
If you right click on the file that needs to be localized, say myImage.png(German), open it in Finder, and replace that file with the right one. Important! The name of the file should stay the same!
I'll post the screenshots later, so it's all clear how to do it.
Using Xcode 9.2
you can achieve it easily like the following
1- From Assets
2- Then you will need to change the Direction option AND CHOOSE BOTH
xcode will allow you to add 3 more image for other language resource
3- add your needed image and use it in story board or from code as well
I have a launch image Default-568h#2x.png which I've localized for English (it sits in my en.lproj folder). Now I'd like to produce one other version of that image for every other language (I've removed the english text from it). How would I go about setting this up? I've tried putting an image with the same name in the top directory but that doesn't work. Do I need to rename to something?
Basically, when you localize to any language (eg: Spanish), you will see another folder such as "es.lproj", the Localizable.strings and other localized files will be there.
You may check http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014
for the step by step instruction on how to do it including localize the image.
Another link that might help: IOS: launch image multiple language
What I did was go into my actual project folder and put the english version of my launch image into a folder called "Launch Image (English)". Then I put the version for the rest of the languages in a folder called "Launch Image (International)" (both images have the exact same name). Then I went into Xcode and attached both folders into the resources section. Then I highlighted each image, clicked on localization in the Utility pane, and for the english version I selected english obviously, and for the other version I selected spanish (then I put a check mark in the check box of each other language in the Utility pane). Then it worked!
Does IB not allow one to specify a localized key for components that display text instead of hardcoding the value? For instance, if you want a UILabel to display internationalized text is the only way to do this via code? Seems like such a PITA to have to set all your label text in code when you have a nice WYSIWYG editor like IB. I think I had this feature back in VB5!
You actually don't normally need to write any code to localize your Interface Builder user interface (Xibs). What you do is create localized versions of these Xibs, with the help of XCode. In your XCode project, select a Xib, open the File Inspector (it's in the Utilities panel) and you'll see a Localization section in there. Click the + button and XCode will create a version for the language of your choice, which you can then localize by translating the text as well as resizing UI elements or do anything else you like.
The normal way in Cocoa/AppKit is to localize the files you want to exist in different languages. But probably the only files you want make localized are your nib/xib files and your strings files.
Clafou has explained how you localize the nib files.
The strings files are files which contain key-value pairs. By calling functions like NSLocalizedString you can query them with the key you've set.
Apple has documented all these features.
Nib files
Strings files