Is it possible to update a localized storyboard's strings?
Asked Answered
C

15

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?

Conditioner answered 26/2, 2013 at 16:29 Comment(1)
developer.apple.com/internationalizationCinerator
D
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

Dahl answered 1/5, 2013 at 7:17 Comment(16)
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.Merwyn
Option 1 works.but you need to change from "Localizable .." to "interface ..." and then back again!Maturate
Build your project first otherwise Option 1 does not work for recently added elementsPressey
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 themGesticulative
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 languageGesticulative
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.Dahl
Option 1 worked for me (not in the beginning, first crashed) but after cleaning derived Data, worked.Peroxidize
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.Steib
@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...Coloquintida
For me Option 1 replaced all already translated strings with English ones. I had to add the translation once again.Damaris
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.Fining
Option 1 was good, but doesn't work anymore after using "refactor to storyboard".Bakehouse
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: https://mcmap.net/q/16795/-is-it-possible-to-update-a-localized-storyboard-39-s-strings I hope you like it!Redolent
how to generate strings for Settings.bundle?Anagnos
You need to translate the whole file again with 1 option!Doubleripper
Option 2 went smoothlyPremonish
R
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.

Redolent answered 14/2, 2016 at 22:14 Comment(5)
Wow! This tool is simply amazing. This needs more upvotes!Gonroff
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 !Maishamaisie
is there a similar pod for OBJC projects?Plotkin
This is the answer we are looking for. This should be the accepted answer.Traylor
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.Hispanic
C
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";
Campaign answered 30/12, 2015 at 15:29 Comment(5)
think it's the less risky approachInfielder
But some of the Object-ID are not show in .string file. Because they are not connected. So at that time what can I do?Comanchean
is there a way to select it via a name and not just the automatic generated id?Eastwood
For a UILabel, its : "YeB-ap-Wkw.text" = "My labels text";Ovovitellin
for me it's not working any more, but 3 years ago it worked...Damales
R
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.

Rube answered 28/5, 2016 at 20:26 Comment(2)
great! Did you also find an idea on how to remove deleted elements?Polyamide
@Polyamide If you split your storyboard as I suggest above, it is really easy to spot the strings that are not used any more.Rube
P
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.

Perrault answered 19/3, 2015 at 12:41 Comment(4)
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.Electrograph
I think so, I've done this a lot of times without any problem.Perrault
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.Haw
Thanks iBug for the explanation =)Perrault
R
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.

Retake answered 13/4, 2016 at 16:11 Comment(3)
+1 Easy and proper way to work with Localization. Moreover it's preferred way be AppleCampman
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.Ung
+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!Paltry
Y
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

Yoakum answered 20/7, 2018 at 10:31 Comment(2)
With Xcode 10 if you use git it highlights the differences!Rave
Yes, It is possible... now my file is bigger than in this date and I merge it with repository version after generate it again.Yoakum
D
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.
Doubleripper answered 26/4, 2017 at 13:22 Comment(1)
For this to work, first select the project or target in the Xcode project editor.Ridinger
A
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).

Abradant answered 16/6, 2014 at 13:39 Comment(3)
The appleglot tool is working with final application bundles. It is a completely different approach for translation applications.Opisthognathous
Anything wrong with a "different approach", or what causes the downvote?Abradant
Need to search AppleGlot in that link now.Cinerator
D
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.

Degust answered 17/3, 2015 at 10:2 Comment(4)
can you provide more information on how to use this?Quay
I added a comment to the gist. Hope it helps. gist.github.com/yoichitgy/29bdd71c3556c2055cc0Degust
Thank you, works perfectly for me. If someone has problems with permissions this could be helpful: stackoverflow.com/questions/9850936/…Baud
This script works fine for storyboard Main.strings files, but seems to be overwriting my Localizable.strings translations in Xcode 7.Fining
B
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.

Boynton answered 3/10, 2018 at 7:44 Comment(1)
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?Charlyncharm
S
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...

Sloe answered 29/10, 2019 at 18:27 Comment(1)
Another alternative for macOS is Loca Studio. 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).Serb
J
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.

Judithjuditha answered 31/3, 2020 at 10:13 Comment(0)
C
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

Cramoisy answered 20/11, 2016 at 13:56 Comment(2)
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 textFifield
@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 github.com/Flinesoft/BartyCrouchCramoisy
N
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.

Niu answered 8/4, 2021 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.