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

82,644

Solution 1

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

Solution 2

Check out BartyCrouch, it perfectly solves your problem. Also it is open source, actively maintained and can be easily installed and integrated within your project.


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.

Solution 3

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";

Solution 4

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.

Solution 5

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.

Share:
82,644

Related videos on Youtube

GeLB
Author by

GeLB

junior iOS developer

Updated on July 08, 2022

Comments

  • GeLB
    GeLB almost 2 years

    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?

  • Reinhard Männer
    Reinhard Männer over 10 years
    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.
  • João Nunes
    João Nunes over 10 years
    Option 1 works.but you need to change from "Localizable .." to "interface ..." and then back again!
  • Tibidabo
    Tibidabo over 10 years
    Build your project first otherwise Option 1 does not work for recently added elements
  • Esqarrouth
    Esqarrouth about 10 years
    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
    Esqarrouth about 10 years
    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
  • Tha Leang
    Tha Leang about 10 years
    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.
  • MiQUEL
    MiQUEL about 10 years
    Option 1 worked for me (not in the beginning, first crashed) but after cleaning derived Data, worked.
  • Flovdis
    Flovdis almost 10 years
    The appleglot tool is working with final application bundles. It is a completely different approach for translation applications.
  • tilo
    tilo almost 10 years
    Anything wrong with a "different approach", or what causes the downvote?
  • Bouncing Bit
    Bouncing Bit over 9 years
    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.
  • Paul Brewczynski
    Paul Brewczynski over 9 years
    @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...
  • Mihail Velikov
    Mihail Velikov about 9 years
    For me Option 1 replaced all already translated strings with English ones. I had to add the translation once again.
  • user023
    user023 about 9 years
    can you provide more information on how to use this?
  • Yoichi Tagaya
    Yoichi Tagaya about 9 years
    I added a comment to the gist. Hope it helps. gist.github.com/yoichitgy/29bdd71c3556c2055cc0
  • iCode
    iCode about 9 years
    Thank you, works perfectly for me. If someone has problems with permissions this could be helpful: stackoverflow.com/questions/9850936/…
  • Adam Johns
    Adam Johns almost 9 years
    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
    Adam Johns almost 9 years
    This script works fine for storyboard Main.strings files, but seems to be overwriting my Localizable.strings translations in Xcode 7.
  • NSDeveloper
    NSDeveloper over 8 years
    Need to search AppleGlot in that link now.
  • Nicolas Manzini
    Nicolas Manzini over 8 years
    think it's the less risky approach
  • darksider
    darksider over 8 years
    Option 1 was good, but doesn't work anymore after using "refactor to storyboard".
  • Jeehut
    Jeehut over 8 years
    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: stackoverflow.com/a/35398661/3451975 I hope you like it!
  • Mihir Oza
    Mihir Oza about 8 years
    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?
  • cocoseis
    cocoseis about 8 years
    is there a way to select it via a name and not just the automatic generated id?
  • ullstrm
    ullstrm about 8 years
    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.
  • jpl850
    jpl850 about 8 years
    I think so, I've done this a lot of times without any problem.
  • Jurasic
    Jurasic almost 8 years
    +1 Easy and proper way to work with Localization. Moreover it's preferred way be Apple
  • duthen
    duthen almost 8 years
    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.
  • Viktor Kucera
    Viktor Kucera over 7 years
    +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!
  • ioopl
    ioopl over 7 years
    For a UILabel, its : "YeB-ap-Wkw.text" = "My labels text";
  • iBug
    iBug over 7 years
    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.
  • jpl850
    jpl850 over 7 years
    Thanks iBug for the explanation =)
  • Chuck Boris
    Chuck Boris over 6 years
    For this to work, first select the project or target in the Xcode project editor.
  • user924
    user924 about 6 years
    how to generate strings for Settings.bundle?
  • ph1lb4
    ph1lb4 almost 6 years
    Wow! This tool is simply amazing. This needs more upvotes!
  • Nike Kov
    Nike Kov almost 6 years
    You need to translate the whole file again with 1 option!
  • Jim75
    Jim75 almost 6 years
    Option 2 went smoothly
  • iKK
    iKK almost 6 years
    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 !
  • rickrvo
    rickrvo over 5 years
    is there a similar pod for OBJC projects?
  • Tobe
    Tobe over 5 years
    great! Did you also find an idea on how to remove deleted elements?
  • Mujahid Latif
    Mujahid Latif over 5 years
    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
  • Fadi Abuzant
    Fadi Abuzant over 5 years
    @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/BartyCrouch
  • Juanjo
    Juanjo over 5 years
    This is the answer we are looking for. This should be the accepted answer.
  • Ricardo Ruiz Romero
    Ricardo Ruiz Romero over 5 years
    With Xcode 10 if you use git it highlights the differences!
  • J. Fdez
    J. Fdez over 5 years
    Yes, It is possible... now my file is bigger than in this date and I merge it with repository version after generate it again.
  • Gerd Castan
    Gerd Castan about 5 years
    @Tobe If you split your storyboard as I suggest above, it is really easy to spot the strings that are not used any more.
  • huggie
    huggie about 5 years
    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.
  • HariKarthick
    HariKarthick over 4 years
    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?
  • guru_meditator
    guru_meditator over 4 years
    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).
  • Ahmadreza
    Ahmadreza about 3 years
    for me it's not working any more, but 3 years ago it worked...