Is it possible to update a localized storyboard's strings? - ios

I localized a part of my application with creating a base.lproj storyboard and 3 string files for it. It was a month ago and after that I added new view controller to app, but this controller's buttons and labels not appear in string files
Is it possible to update this 3 storyboard attached string files or I must add new strings translations programmatically with using NSLocalizableString and Localizable.strings?

There are two options:
Option 1
Xcode can "reload" the file by converting the file to either an [Interface Builder Cocoa Touch Storyboard] file type or a [Localizable Strings] file type.
Select your base storyboard file from the Project Navigator
Find the Localization section in the File Inspector
If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
Xcode should have converted your storyboard to the current version, while preserving your old localization efforts. Here you can change the file back to the original file type if you would like.
Option 2
Use ibtool to extract the strings in your storyboard.
Open the Terminal application
Locate your Base.lproj directory
Use this line to extract the strings:
ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings
After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file
Visit for more info: https://conyac.cc/business/columns/localization_guide_ios

Check out ReMafoX, it's a Mac app that perfectly solves your problem. It can be easily installed and integrated within your project, watch this video for a detailed walkthrough.
Alternatively, if you prefer an open source CLI tool without a GUI, you can also use BartyCrouch.
Install BartyCrouch via Homebrew:
brew install bartycrouch
Alternatively, install it via Mint:
mint install Flinesoft/BartyCrouch
Incrementally update your Storyboards/XIBs Strings files:
$ bartycrouch update
This will do exactly what you were looking for.
In order to keep your Storyboards/XIBs Strings files updated over time I highly recommend adding a build script (instructions on how to add a build script here):
if which bartycrouch > /dev/null; then
bartycrouch update -x
bartycrouch lint -x
else
echo "warning: BartyCrouch not installed, download it from https://github.com/Flinesoft/BartyCrouch"
fi
In addition to incrementally updating your Storyboards/XIBs Strings files this will also make sure your Localizable.strings files stay updated with newly added keys in code using NSLocalizedString and show warnings for duplicate keys or empty values.
Make sure to checkout BartyCrouch on GitHub or this detailed article for additional information.

You can manually add a key in your localization file. You can find the key object by selecting it on storyboard editor. Let's have a look at Object-ID in the identity inspector. It's look like "nwc-b2-19c"
On your localization update or add translation. For example :
"nwc-b2-19c.title" = "Translated title";

This one is not for everybody, but it requires no additional tools in the terminal and it's easy for small manual changes. (Do not consider this when you want to automate your process.)
Step 0: Storyboard language setup
Base (with english texts)
English (localizable strings file does not exist because the base file is english)
other languages (localizable strings files)
This step is done only once.
Now when I add something to the storyboard I do the following
Step 1: add the English localizable strings file
just mark the English line item.
This creates a completely new english localizable strings file with all the lines
Step 2: copy the new line items into the other language files
and translate them
Step 3: unmark English, remove the corresponding localizable strings file
the file was only needed to get the new line items
This is an easy and fast process, everything is done in the storyboard editor
Edit:
This process works very well with small storyboards. For example, I have a tabs based project and I have a storyboard for each tab.
Search for "storyboard reference" to find tutorials.
Good example: Storyboard reference in Xcode, where should we use it?
So each small storyboard only has a few strings to localize.

Finally, my solution was (rudimentary but effective) copy the previous translations and paste them in the a new file created by unchecking and checking the Localization language box.
This would be useful in some cases like mine when you have to change only one or two texts.

I think the best way is by using built-in export/import Localizations:
In Project Navigator choose you project folder
Choose Editor > Export For Localization,
All translations left on their places and XCode add missed strings automatically.
Additionally, before import, you can edit .xliff in XLIFF Editor (for example, online - http://xliff.brightec.co.uk) and then you don't need to do this in XCode.
then Editor > Import Localizations and choose saved .xliff file.
P.S. If you don't want to edit in XLIFF Editor and have skipped step 3, XCode can didn't save new strings. In this case open .xliff in XLIFF Editor, re-save without changes and import new file.

When you click in your storyboard, Main.storyboard for example... On right side you can see the localization menu (see atached image). If you uncheck and check again a lenguage, the file will be generated again. So I usually copy the content, I generate the file again and then I paste the content that I copied and already been translated.
This is the way that I use to update the dictionary.

I got a huge storyboard with a lot of strings there. Two languages base english and another arabic. The task was to add some fields and labels to storyboard and add localization for them without any scripts and NSLocalizableStrings.
For me helped next:
First: Ensure, you have git to prevent unexpectable changes.
Go to target screen in xcode and press Editor -> Export For Localization.... Save the ar.xliff file somewhere.
Download XLIFF Edtior.
Open ar.xliff file and make changes.
Import this file in xcode. Done! You have updated storyboard strings file.

There is an app a command line tool from Apple named AppleGlot that supports incremental localisation. I haven't tried it yet, but it looks exactly like the tool you searched for (some time ago).

Here is a script to extract strings from storyboards and xibs, and merge them with existing translations.
To run the script automatically when you build a project, put the script into your project root directory, and add a Run Script phase with the following line to a target build phases in your project settings.
./mergegenstrings.py PathToSourceDir
Or you can run the script on Terminal manually when you want to.
The script runs ibtool as Tha Leang answered. It also runs genstrings to extract and merge strings marked with NSLocalizedString in your source code. The script is based on a script in this post, which merges strings after running genstrings.

The easiest and very less risky approach is, just copy the Object ID from the storyboard and add a new key for the key in the localized file as below example:
1: Copy object id as below from storyboard for the component:
2: Add new key in localised file like below:
"DjF-dn-0ay.text" = "Borrar datos y restablecer";
Note: This is very less risky approach if you want to update only few component otherwise you can recreate localised file for the storyboard.

Xlifftool is available as a Mac app and works well. It shows all the translatable strings and objects from info.plist, localizable strings, and the storyboard.
Get it here for the mac: https://itunes.apple.com/lv/app/xlifftool/id1074282695?mt=12
Step 1: in Xcode, select your project folder in the project navigator. Then select Editor/Export for Localization...
Your translatable strings will be included in an xliff file under the language you selected for localization in Xcode.
Step 2: Open that file with xlifftool and translate or update your translations there were done previously.
Step 3: Then upload back into your project with Editor/Import Localizations...

Option 1
Xcode can “reload” the file by converting the file to either an [Interface Builder Cocoa Touch Storyboard] file type or a [Localizable Strings] file type.
Select your base storyboard file from the Project Navigator
Find the Localization section in the File Inspector.
If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
Xcode should have converted your storyboard to the current version, while preserving your old localization efforts. Here you can change the file back to the original file type if you would like.
Option 2
Use ibtool to extract the strings in your storyboard.
Open the Terminal application
Locate your Base.lproj directory
Use this line to extract the strings:
ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings
After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file.

This is my easy way to update new text from storyboard or xib to localization string
1- use this script http://tredje.se/dev/trouble/?x=entry:entry150917-204052
2- select your localization string that you want to update and switch your language string from "Localization string" to "interface builder storyboard"
3- switch it back :)
Done.

Add a new language to localise. One that you do not need.
It will produce say Indonesian.strings for example which will contain all the storyboard buttons-names etc which you need, copy and paste all of them into all the other language.string files you have.

Related

XCode 9 localization export/import doesn't include NSLocalizedString() or comments

Situation:
We use XCode exporting/importing tools to generate localizable files for our translators. This was going fine in XCode 8. Since we updated to XCode 9 we see a couple of problems.
Problems:
When exporting a localization via Editor-->Export for localization...-->Development language only, it doesn't include NSLocalizedString() key/values as it should according to this documentation: When you export localizations, Xcode searches your code for the macros and includes the strings files in the exported localization file for translation.
Comments that are added to the Localizable.strings development-language file seem to be non-existent in the export .xliff file.
When importing a translated .xliff file, XCode seems to delete all the comments that are in the file. It gets replaced by "(No Comment)"
Configuration:
XCode 9.0 (9A235)
Dev language: NL
Localized languages: Base, NL, DE, BE, LU
Objective-C & Swift hybrid project
What I've tried:
I have tried looking at XCode 9 documentation or changelog to see what has changed in Localization, though nothing I can find mentions this change
I can get my NSLocalizedString() strings to show up in the export when I first generate the development Localizable.strings file manually, by using the commandline command find ./ -name "*.m" -print0 | xargs -0 xcrun extractLocStrings -o . (I run it a second time for .swift files as my project is a swift/objc hybrid). Then combine the results, which let my strings show up in the export, however without comments, which are needed as guides for translators.
Question:
Is this an XCode 9 bug? Did I miss any documentation or new feature/option for localization exports/imports? Are there workarounds?
This is an older question, but I had this same issue with Xcode 10.
The solution is to simply place the strings files (e.g. InfoPlist.strings) in the same folder as plist.info. Only then are existing translations included in localization exports.
Previously I had them in a dedicated "Localizations" group. While this works for the localization itself (i.e. when running the app), localization exports seem to only include translations from existing strings files that are "near" plist.info.
What fixed both importing and exporting for me was turning off Base Internationalization by unchecking Use Base Internationalization under Project > Info > Localizations. I set all my translations in code, so I don't need it enabled for my .storyboard and .xib files.
Previously, when it was enabled, the "Localizable.strings (Base)" file didn't have anything in it, but Xcode 8 still seemed to work properly by using what was in my "Localizable (English)" file when exporting. For Xcode 9, if I had the source text in Localizable (Base) then exporting worked fine, but I still had problems with importing.
I am using Xcode 9.4.1.
I finally found the reason of the issue.
The issue exists because Xcode never saved files in the encoding it promised.
There are two places to set text encoding, one is "Default text encoding", which including a "convert existing files on save" checkbox.
There is also a file specified "Text Encoding" on each file when you open it. If you don't specify the text encoding on the file, the "Default text encoding" is used.
However, Xcode never saved the file as it promised. For example, if you choose a file specified text encoding, say to "UTF-16", an alert window shows with "Cancel", "Reinterpret", "Convert".
As the alert said, if you chose convert, Xcode would convert the file to the encoding. However, it didn't.
So when you exporting the translations, the file is opened with the encoding it never converted to and ignored.
You can verify that by these steps.
choose a source file.
change it to another text encoding.
in the alert window, choose convert
in Xcode, right click the file and choose Show in Finder.
quit Xcode.
open the file with another text editor that can deal with text encoding, mine is BBEdit.
in BBEdit, choose file -> save as
Now you can see, that the file is not saved in the encoding as it promised.
Solution
The solution is easy. For files that you specified the text encoding, keep it saved in the encoding that it specified. You can do that with other editors, like BBEdit, by save as and choose the right encoding.
For those files that are not specified text encoding. Be sure them are saved as "Default text encoding". If not, change the "Default text encoding" so you won't need to change each file.

One localization source for code and design

Is there any way to use just one file for localizing texts in Xcode 7 and above?
Maybe some kind of macro/script in Xcode.. whatever..?
I mean making the storyboard/IB resources to use the words directly from a Localizable.strings file instead of having the code using the texts from localizable and the storyboad having their own localization files.
Please share your opinions/solutions about that. Also please do not mention the solution of entering everything through code, that does not seem valid/recommended.
Here's how you can consolidate your localisable content into a single file to send out for translation:
With your Xcode project open, select the project file
Editor -> Export for Localization...
Follow the steps
You will then get an .xliff file for each language that you want to have as part of your app. Send this out to your translators, and they will send it back, with the localised content. Once that's done, simply do the same steps, but for importing instead:
With your Xcode project open, select the project file
Editor -> Import Localizations...
Follow the steps

Xcode removing language specific storyboards iOS

A while ago i decided to make my application multilanguage. I ended up using localizable.strings. So a different file for each language with all the translations in it.
In my main storyboard i just use NSLocalizedString(#"example", nil); on all my elements etc.
The problem i have is that i just found out that i somehow ended up with a storyboard for each language. I can fold out my MainStoryboard_iPhone.storyboard and under this it lists the language specific storyboards (MainStoryboard_iPhone.storyboard (English) and MainStoryboard_iPhone.storyboard (Dutch). Since i do not use this because i do everything with the localizable.strings i do not need this language specific storyboards. Over time they also became inconsistent. The english board has all the current changes and the dutch one does not.
My question is:
How can i safely remove these language specific storyboards and just keep using the localizable.strings. I want to end up with only 1 main storyboard (the top level one in the image above). I do not want to ruin my project and i want to be sure that the solution i use is correct.
Thank you!
I had the same issue.
I solved it by selecting "Base internationalization" in the project settings. Next, click the file inspector icon (right pane) for your storyboard file and make sure only Base is checked. Do not check the other languages.
This will fix the issue.
Don't bother with Base internationalization for your localizable.strings file, you can still use your regular translation setup there (ie, English and Dutch).
To "roll back" a localized File. you have to navigate to the folder where your class should be. You see the folder "en.lporj" (and the other languages) and there is the file you need.
-
Now copy to a save place, remove the multi-language file and in xcode and tell to remove from disk. Copy it again into your folder where you need it and import it in xcode.
Now the settings for the translation are resettet. you should recheck if no links went lost (simple clean build should be enought for this).
I handle only .xib file at the moment, but the procedure should be the same for all files :)
(if not, please let me know :D)
Greets,
geo

I deleted the Localizations in Xcode, then I cannot add any Localizations back

I deleted the Localizations of the project from the project's info by mistake. Both the storyboard and the related language were removed.
I got back the storyboard from previous file but when I want to add a new Localization, a window popped out and asked me to "Choose files and reference language to create English localization" and there is no resource file at all.
How can I add back the localizations?
Adding back a localization
When you delete your localizations sometimes you can get that situation where you can't add back any localizations in Xcode. Go to the command-line and create a ISO 639-1 two-letter language abbreviation folder with the lproj extension somewhere within your project.
Create an empty language folder
For example:
${SRCROOT}/Resources/Translations/nb.lproj
or
${SRCROOT}/Resources/Translations/en.lproj
Re-add language files to project
In the folder create an empty file called Localizable.strings and add this file to your project. Don't add the .lproj folder, just the contents. Then when you go back into the project file you will see the language under localizations. Now when you have added this, you should see the localization in your project.
No checkbox
If the added file, like a storyboard, doesn't have a checkbox next to it indicating that is part of that language localization you might need to round trip them through another language. To do this add a new language in the project. It should prompt you to copy the existing localized files over to the new language. Then delete the broken localization and re-add it.
My Example
As a specific example, I added the storyboard in the nb.lproj directory to the project. The Norwegian Bokmål appears in the project, but the checkbox for the language in the storyboard inspector won't let me add it. I created nb_NO in the project and it prompted me to copy over the storyboard. Then the storyboard had that checkbox checked. I deleted the 'nb' localization and re-added it. Now everything was the way I wanted it.
I had to solve same problem, and found one solution:
You need to find in finder your *.xcodeproj file and open it as container (ctrl+click on it and you will see it in context menu)
Here you can see project.pbxproj file, open it in Xcode. Its large (but still readable file).
(it will be better to make some copy on save spot, before you start)
Now its the task to add the missing language to this file, and its done.(U can try it on other project with localizations).
There is paragraph you need to add. Search in this file for this /* End PBXSourcesBuildPhase section */(its paragraph right before localization paragraph which is missing) and add something like this after:
/* Begin PBXVariantGroup section */
27548D921611B0BE008EA1CD /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
27548D941611B0BE008EA1CD /* en */,
);
name = Localizable.strings;
path = ../Code;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
You have to do some changes first. Look at the long number 27548D921611B0BE008EA1CD, its ID of the localization file (or some xib file, or other localizable file...), if you dont have any in the procject, just add some Localizable.string file to the project, reopen(or refresh) this project.pbxpro, and find this Localizable.string you should find something like this:
275490591611B0BE008EA1CD /* Localizable.strings in Resources */
and this is it what you need to replace in localization paragraph
also you need to do right settings on path parametr and sourceTree. This twos are readable in fileinspector in xcode.
The "sourceTree" param is Location - mostly its relative to group so sourceTree = "<group>";
The path is path relative from the group to the file (if you dont know, try to make some localization files in different project and look at project.pbxpro, what all this works)
After this you can save project.pbxpro, and you should see in xcode info section "en" localization and you can add more localizations and all other localization stuff.
In xcode 6, do the following:
With the command line, create the following directory/file structure somewhere outside your project directory:
/en.lproj/InfoPlist.strings
/en.lproj/Localizable.strings
In Xcode, open your project and choose File>Add Files to ProjectName to add the recently created en.lproj directory.
After that, you will see English in the Localizations list.
This is an old topic, but after having this issue, and then trying the solution (and having it not work exactly), I thought I'd give details on what DID work.
Like the original poster, I accidentally deleted all of my localizations and was given no obvious recourse in Xcode-- in the project settings under Info it simply said 'this project has not been localized', and when I clicked on the plus button beneath, a blank list of resource files was presented.
I followed #Cameron's guide but found that language folders with Localizable.strings files were already present in Finder, but weren't being acknowledged by Xcode. I couldn't decide how to proceed, but I happened to see an unrelated comment about adding files to Xcode, so I tried adding the existing en.lproj folder and its Localizable.strings file.
This worked, and the listing for English as the development language appeared under Info as well.
Hopefully this will help anyone who experiences the same problem!
Simply create a Folder "Base.lproj" in finder and paste the Xib you want to localize inside it, and add this folder to your project. Now you can able to add other languages without issue.
I've followed a similar approach of #user2070775 reply.
Firstyl when you delete Storyboard and Launchscreen to use your own creation or code programmatically, on Localization you might get similar following empty screen.
Then firstly you should know the language code for example to use French localization its fr etc
With project folder in the Project Navigator you must add New Group -> {LANGUAGE_CODE}.lproj. And then you should add New File -> Strings File -> Localizable.strings. In the #user2070775 answer, also InfoPlist.strings file has added so I added too for now.
In the Localizable.strings file you can add <KEY> = <VALUE> pairs for string to localizated.
Our pair is "this-is-key" = "and-this-is-value-for-spesific-language-on-localizable-string"; for now.
HINT: In key-value pair, when I did not put the semicolon, the XCode
gives error for this situation.
Until now, the following project scheme, must the result of you have.
Additionally, when you looked at the Project -> Info -> Localizations the French or etc. language must be added like in the following image.
TESTING
Basically you can get the results of the what've you done
The remaining part can be set from the Simulator. You must change the simulator language, for this answer the correct one is French.
Go to Settings -> General -> Language & Region -> French and run the project again.

How do you add localization to the Settings bundle under source code control

I am trying to localize my Settings.bundle. There does not appear to be anything in Xcode 4 that allows you to add localization to the Settings.bundle similar to localizing a xib file. So I used finder to navigate to the Settings.bundle and copied the en.lproj directory to create directories in the bundle called fr.lproj and de.lproj. From there, you can modify the strings file to localize the titles in the Root.plist.
But the problem is that the new directory is not under source code control. If I try to add the directory to source code control, I get the following error: The operation could not be performed because the selection is invalid.
How can I resolve this problem and get the new settings.bundle directory under source code control?
Correct strings file format is:
"Title" = "title in correct language";
Pay attention "Title" from Root.Plist NOT "Identifier"
What you are doing is right. I can't explain why you are unable to add your new subfolders/files to source control. I have the exact same structure in an iOS project of mine and these files are under source control like all the others. I don't recall having difficulties adding them.
Have you tried using git commands directly to add them? The integration in XCode is great but in my experience there are time when you do have to use the command line for git.

Resources