235

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?

GeLB
  • 2,351
  • 2
  • 13
  • 5

15 Answers15

272

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.

  1. Select your base storyboard file from the Project Navigator
  2. Find the Localization section in the File Inspector
  3. If your file is currently a [Localizable Strings], change it to [Interface Builder Cocoa Touch Storyboard] or vice-versa.
  4. 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.

  1. Open the Terminal application

  2. Locate your Base.lproj directory

  3. Use this line to extract the strings:

    ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings

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

Community
  • 1
  • 1
Tha Leang
  • 3,070
  • 1
  • 16
  • 14
  • 1
    I tried Option 1, but changing the file type from [Localizable Strings] to [Interface Builder Cocoa Touch Storyboard] results always in a crash of Xcode 5.0.1. The reason might be that - because I was not aware of the possibilities above - I edited the storyboard localization files by hand earlier. – Reinhard Männer Nov 25 '13 at 08:03
  • 16
    Option 1 works.but you need to change from "Localizable .." to "interface ..." and then back again! – João Nunes Dec 27 '13 at 16:27
  • Build your project first otherwise Option 1 does not work for recently added elements – Tibidabo Feb 10 '14 at 00:13
  • option 1 worked for me before. now I added a new view and when I try to use this technique it converts to strings without a problem, except it uses the old version. (without my new added view). when I change those strings back in to a storyboard, it messes up something, the result is storyboad that contains stuff from 2 different languages randomly. Like one button says : hello, other bonjour, when both of them should have bonjour on them – Esqarrouth Mar 23 '14 at 17:14
  • i tried option 2, no problem in changing and translating strings. but the problem is, my storyboard didnt change, i only changed the texts manually, it didnt add a new view in my app when i run it on another language – Esqarrouth Mar 24 '14 at 01:25
  • Option 3 (Actually, the option I found most maintainable for me): Keep all your text inside .strings files. I found that I needed to frequently grab the labels to change the font sizes and style depending on the language anyways, so it worked out best for me to keep all text out of the storyboards and just use the .string files. – Tha Leang Mar 25 '14 at 01:57
  • Option 1 worked for me (not in the beginning, first crashed) but after cleaning derived Data, worked. – MiQUEL Apr 23 '14 at 00:22
  • 3
    Option 1 doesn't work for me using XCode 6.0.1. When trying to convert my .strings file to .interfacebuilder XCode asks if the files should be converted. The files get created on the file system, however the string files still remain and contain the old values. – Bouncing Bit Oct 07 '14 at 19:56
  • 1
    @ThaLeang I would replace the order of options. Option 2 seems more reliable. And reliability is what we need when we can loose all translation by mistake... – Paweł Brewczynski Dec 10 '14 at 08:21
  • 55
    For me Option 1 replaced all already translated strings with English ones. I had to add the translation once again. – Mihail Velikov Mar 04 '15 at 09:24
  • 5
    Option 1 seems very unstable in Xcode 7. Sometimes it works, sometimes it doesn't. Sometimes it randomly replaces some of my already translated strings with english versions again. – Adam Johns Jul 19 '15 at 23:07
  • Option 1 was good, but doesn't work anymore after using "refactor to storyboard". – darksider Feb 07 '16 at 21:11
  • I created a command line utility that automates a similar approach to option 2. You can integrate it as a build script which allows you to forget about updating your `.strings` files, instead of manually updating them each time you make a change as described here. See my answer for further details: http://stackoverflow.com/a/35398661/3451975 I hope you like it! – Jeehut Feb 15 '16 at 07:36
  • how to generate strings for Settings.bundle? – user924 Apr 06 '18 at 07:41
  • 2
    You need to translate the whole file again with 1 option! – Nike Kov Jun 11 '18 at 10:20
  • 1
    Option 2 went smoothly – Jim75 Jun 21 '18 at 09:39
88

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.

Jeehut
  • 20,202
  • 8
  • 59
  • 80
  • 1
    Wow! This tool is simply amazing. This needs more upvotes! – ph1lb4 Jun 10 '18 at 09:38
  • 1
    lovely tool - no more manual copy/pasting of new label-texts in *.strings-files (...and forgetting any new label's translation as before)... Thanks a lot ! – iKK Aug 16 '18 at 09:48
  • is there a similar pod for OBJC projects? – rickrvo Aug 29 '18 at 19:26
  • 2
    This is the answer we are looking for. This should be the accepted answer. – Juanjo Sep 15 '18 at 21:11
  • 6
    I don't get why after 6 years since this question is asked and this patchy solution is still required to get this to work in Xcode. Apple should have worked on this. – huggie Mar 15 '19 at 03:21
57

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";
huzeyfe
  • 3,554
  • 6
  • 39
  • 49
Sébastien REMY
  • 2,399
  • 21
  • 39
35

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)

base configuration

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

Add English

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.

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
15

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.

jpl850
  • 374
  • 3
  • 11
  • Would this preserve the id's and such all the time? I did one test and it seemed to work, but it could be a disaster if the id's changed. – ullstrm Apr 17 '16 at 18:37
  • I think so, I've done this a lot of times without any problem. – jpl850 Apr 18 '16 at 18:06
  • 1
    IDs are assigned when you dropped the UI elements. They are independent of localisation as they are assigned by storyboard. So there will be no effect on IDs. – iBug Dec 08 '16 at 06:50
  • Thanks iBug for the explanation =) – jpl850 Dec 08 '16 at 09:06
14

I think the best way is by using built-in export/import Localizations:

  1. In Project Navigator choose you project folder
  2. Choose Editor > Export For Localization,
  3. 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.
  4. 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.

Igor
  • 12,165
  • 4
  • 57
  • 73
  • 1
    +1 Easy and proper way to work with Localization. Moreover it's preferred way be [Apple](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html) – Jurasic May 23 '16 at 07:48
  • 1
    Using Xcode 7.3.1, in an already localized sample project, I changed a label (from "a text" to "a basic text") and I added a new label. I exported for localization, touched the .xliff file (with no change) and imported it again. In the Main.strings file, the comment line for the changed label has been updated `/* Class = "UILabel"; text = "a basic text"; ObjectID = "HFW-aN-MTb"; */`, but the new label is NOT created in the Main.strings file. Then I edited the .xliff file to add a translation for the new label. I imported it again. The new label is now inserted in the Main.strings file. – duthen May 27 '16 at 08:04
  • +1 but there is a bug I've discovered. When adding new elements they are not in an exported file (like duthen is saying). But when I do an export right after (with no changes to storyboard) all added elements are, surprisingly, included. So do an export twice. The second one will include all new elements. Thanks Apple! – Viktor Kucera Oct 06 '16 at 08:20
7

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.

enter image description here

J. Fdez
  • 156
  • 2
  • 5
6

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.

  1. Go to target screen in xcode and press Editor -> Export For Localization.... Save the ar.xliff file somewhere.
  2. Download XLIFF Edtior.
  3. Open ar.xliff file and make changes.
  4. Import this file in xcode. Done! You have updated storyboard strings file.
Nike Kov
  • 12,630
  • 8
  • 75
  • 122
4

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

tilo
  • 14,009
  • 6
  • 68
  • 85
4

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.

Yoichi Tagaya
  • 4,547
  • 2
  • 27
  • 38
  • can you provide more information on how to use this? – user023 Mar 20 '15 at 17:02
  • 1
    I added a comment to the gist. Hope it helps. https://gist.github.com/yoichitgy/29bdd71c3556c2055cc0 – Yoichi Tagaya Mar 22 '15 at 17:39
  • Thank you, works perfectly for me. If someone has problems with permissions this could be helpful: http://stackoverflow.com/questions/9850936/what-permissions-are-required-for-run-script-during-a-build-phase – iCode Apr 10 '15 at 12:58
  • This script works fine for storyboard Main.strings files, but seems to be overwriting my Localizable.strings translations in Xcode 7. – Adam Johns Jul 20 '15 at 00:47
4

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:

enter image description here

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.

Alok
  • 24,880
  • 6
  • 40
  • 67
  • Thanks for your answer!!!!!. I have a question to ask, In my projects, I have not created an outlet for some of the labels, buttons... If I use objectID for those buttons and labels is it enough? – HariKarthick Nov 01 '19 at 05:49
3

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

TM Lynch
  • 403
  • 3
  • 13
  • Another alternative for macOS is [Loca Studio](https://www.cunningo.com/locastudio/index.html). Similar to Xlifftool, the app can open the result of the Xcode action Editor -> Export for Localisation. It has some more advanced filtering and search features, and also automatic QA checks. (full disclosure: I am the lead developer). – guru_meditator Jan 21 '20 at 04:57
2

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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
0

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.

enter image description here

Fadi Abuzant
  • 476
  • 8
  • 13
  • It does change the file to Interface Builder Storyboard but than again after 1 or 2 seconds revert it back to Localizable Strings and no addition to Localizable Strings for new view text – Mujahid Latif Sep 14 '18 at 08:03
  • @MujahidLatif I'm using this Pod right now, it's really useful to me and it's can update storyboard localizations and Localization.String as will https://github.com/Flinesoft/BartyCrouch – Fadi Abuzant Sep 14 '18 at 20:03
0

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.

jamesphuket
  • 11
  • 1
  • 1