Is it possible to update a localized storyboard's strings?
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.
- 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
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)
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.
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.
Related videos on Youtube
Comments
-
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?
-
NSDeveloper over 8 years
-
-
Reinhard Männer over 10 yearsI 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 over 10 yearsOption 1 works.but you need to change from "Localizable .." to "interface ..." and then back again!
-
Tibidabo over 10 yearsBuild your project first otherwise Option 1 does not work for recently added elements
-
Esqarrouth about 10 yearsoption 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 about 10 yearsi 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 about 10 yearsOption 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 about 10 yearsOption 1 worked for me (not in the beginning, first crashed) but after cleaning derived Data, worked.
-
Flovdis almost 10 yearsThe
appleglot
tool is working with final application bundles. It is a completely different approach for translation applications. -
tilo almost 10 yearsAnything wrong with a "different approach", or what causes the downvote?
-
Bouncing Bit over 9 yearsOption 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 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 about 9 yearsFor me Option 1 replaced all already translated strings with English ones. I had to add the translation once again.
-
user023 about 9 yearscan you provide more information on how to use this?
-
Yoichi Tagaya about 9 yearsI added a comment to the gist. Hope it helps. gist.github.com/yoichitgy/29bdd71c3556c2055cc0
-
iCode about 9 yearsThank you, works perfectly for me. If someone has problems with permissions this could be helpful: stackoverflow.com/questions/9850936/…
-
Adam Johns almost 9 yearsOption 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 almost 9 yearsThis script works fine for storyboard Main.strings files, but seems to be overwriting my Localizable.strings translations in Xcode 7.
-
NSDeveloper over 8 yearsNeed to search AppleGlot in that link now.
-
Nicolas Manzini over 8 yearsthink it's the less risky approach
-
darksider over 8 yearsOption 1 was good, but doesn't work anymore after using "refactor to storyboard".
-
Jeehut over 8 yearsI 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 about 8 yearsBut 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 about 8 yearsis there a way to select it via a name and not just the automatic generated id?
-
ullstrm about 8 yearsWould 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 about 8 yearsI think so, I've done this a lot of times without any problem.
-
Jurasic almost 8 years+1 Easy and proper way to work with Localization. Moreover it's preferred way be Apple
-
duthen almost 8 yearsUsing 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 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 over 7 yearsFor a UILabel, its : "YeB-ap-Wkw.text" = "My labels text";
-
iBug over 7 yearsIDs 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 over 7 yearsThanks iBug for the explanation =)
-
Chuck Boris over 6 yearsFor this to work, first select the project or target in the Xcode project editor.
-
user924 about 6 yearshow to generate strings for Settings.bundle?
-
ph1lb4 almost 6 yearsWow! This tool is simply amazing. This needs more upvotes!
-
Nike Kov almost 6 yearsYou need to translate the whole file again with 1 option!
-
Jim75 almost 6 yearsOption 2 went smoothly
-
iKK almost 6 yearslovely 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 over 5 yearsis there a similar pod for OBJC projects?
-
Tobe over 5 yearsgreat! Did you also find an idea on how to remove deleted elements?
-
Mujahid Latif over 5 yearsIt 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 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 over 5 yearsThis is the answer we are looking for. This should be the accepted answer.
-
Ricardo Ruiz Romero over 5 yearsWith Xcode 10 if you use git it highlights the differences!
-
J. Fdez over 5 yearsYes, 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 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 about 5 yearsI 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 over 4 yearsThanks 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 over 4 yearsAnother 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 about 3 yearsfor me it's not working any more, but 3 years ago it worked...