How to sync localized storyboards' strings after modifying storyboard in Xcode 5
Asked Answered
F

8

42

I'm just starting to look at IOS Apps' localization in XCode 5 and I've tried to add an Italian Localization: Adding Italian Localization

Xcode 5 automatically generates the Main.strings file with a single entry, for the only label I've put within the Main.storyboard file:

/* Class = "IBUILabel"; text = "Label"; ObjectID = "PeT-4z-NSf"; */
"PeT-4z-NSf.text" = "Etichetta";

XCode 5 generated file

If I later modify the Main.storyboard file adding a new button to the view, then how should I tell Xcode 5, if possible, to add missing localization strings to the Main.strings file? Should I add a new entry by hand by looking at the Object ID field in Interface Builder (it works, but I don't know if this is how it is meant to update storyboards' localization)? Can I run something like genstrings on the Main.storyboard file to extract all the labels' text and add the new ones to the localized Main.strings files?

Frontolysis answered 2/1, 2014 at 23:22 Comment(3)
Hello Gianni, Did you find any solution for this from other sources. I too need this,if you come to know plz update the solution here.It helps me and those who come across this post.Dialysis
Look at answer to this SO question: #15094759Annalist
I posted a clean solution to this problem here: https://mcmap.net/q/16795/-is-it-possible-to-update-a-localized-storyboard-39-s-stringsBetweentimes
B
20

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 for additional information.

Betweentimes answered 6/5, 2016 at 17:5 Comment(9)
Nice Work Dschee, you BartyCrouch solution seems to work great!Hanger
I've tried this solution but I keep getting Error! No input files found. on bartycrouch. I've tried inputting workspace dir, project dir, and project file itself. they all result the same.Furze
@CanPoyrazoğlu Thanks for reporting this. Could you please make sure you're not running into this issue? There's currently a problem with projects that have whitespaces in their name. If this doesn't solve your problem, please open an issue on GitHub with additional information (best would be an example project).Betweentimes
@Dschee my project path doesn't have any whitespaces (neither in any parent directories or in itself). I'll have a deeper look when I have time.Furze
Please also note that there is this issue around. Maybe you're in a similar situation? Basically them problem can arise if you have specified multiple languages for your project but some of your localized files are not localized in all of them. I'm planning to make BartyCrouch more resilient against this case sometime. For the moment use the workaround described in the issue if that situation applies.Betweentimes
Biggest problem of bartycrouch right now for me is the installation for xcode 7Schild
@thibautnoah I'm sorry, I don't have enough spare time to continue support for Xcode 7 in addition to the latest Xcode version. But feel free to download any version below 3.3.0 (3.2.3 being the latest) and build BartyCrouch manually. That should work with Xcode 7 – don't forget then though, that you would need to read the appropriate version of the README for usage instructions. It should not be much different from the current version though, as there was no major release since 3.2.3 as of now.Betweentimes
@thibautnoah One more idea I have is: You can fork github.com/Flinesoft/homebrew-bartycrouch and revert it to the commit where it was updated to support version 3.2.3. Then you should be able to install BartyCrouch version 3.2.3 via Hombrew by running the following to commands: brew tap <your-username>/bartycrouch and brew install <your-username>/bartycrouch/bartycrouch. If it doesn't work, might try to untap the official source first with brew untap flineswoft/bartycrouch. Haven't tried this, but might work.Betweentimes
I've tested it with my own project on Xcode 8.3.1, it worked great. Thank you for your work and time. +1. It's just a shame that Xcode does not have a tool like this embedded.Quern
S
19

The file that Xcode does not update automatically (at least 5.x version didn't) is the app's Localizable Strings. You can build a fresh file from Main.storyboard as follows:

In the project Navigator (the leftmost pane) click on the Main.storyboard file. In the Utilities pane (the rightmost pane) click on Show the File inspector icon. It is the leftmost icon in blue in the image below:

File inspector is the leftmost icon.

On the right pane that will appear, one of the sections will be Localization:

Localization section

Uncheck the English (Localizable Strings) row and in the window that will pop-up check the Delete localized resource files from disk and click the Remove button (you do not have to check delete, in which case Xcode will ask for a permission to override it when you build it next).

Then check English (Localizable Strings) again to build it from scratch.

Sublimation answered 15/10, 2014 at 22:36 Comment(3)
This means that if you localize some other language than english, everything will be removed and once you "re-add" all the translation will be overwritten with the ones from the storyboardForewarn
Unless one uses the very specific workflow assumed by Apple (which is, as mentioned in one of the comments here, definite overkill for small projects) maintaining translations in Xcode is extraordinarily painful. Your answer describes so far the best way to do it manually, but it's not perfect either. The order of the strings occasionally changes after recreating the string file. If you then use a diff tool to keep the other languages in sync you have to rearrange some lines. Anyway, given there is no better method, this is the way.Bifilar
@Forewarn have you find something?Enwrap
S
6

Using Xcode 6 the following worked for me:

I changed the localization for a language from "Localizable Strings" to "Interface Builder ..." like suggested at the SO question posted by h.orim. However the setting did not change, it still was set to "Localizable Strings". The next step now is to do that again, so Xcode will find the Storyboard it just created and show a prompt asking if it should be used or replaced. Now click on "Use file" instead of "Replace", otherwise the same will happen again.

Now you should have a localized Storyboard in the desired language. After you now switch back to "Localizable Strings" you will have a file containing all current strings used in the storyboard with your previous translations still in place.

Seldom answered 4/11, 2014 at 12:54 Comment(2)
thanks for that, saves a great deal of time, now why in the world isn't Apple simply making an "update" for this that does about the same thing, but obviously with a single click. but it actually missed a tool tip? strange. maybe it misses all tool tips. actually it did miss a common title too.. so be careful.Measly
ok it appears to happen when you add for instance an accessibility tag where you didn't have one before, but had a tooltip tag before. Geez Apple.Measly
A
6

Another way is to do it manually by selecting on the storyboard the field to translate. Go to the "Identity Inspector" and copy the Object ID (something like HP8-op-SmX).

identity inspector

After that, open the storyboard langage file (Main.strings, most cases) and past the Object ID. Depending your needs, you just have to add .text or .placeholder.

   "HP8-op-SmX.placeholder" = "My translated placeholder text";
   "HP9-op-VvD.text" = "My translated text";

Save, clean & build. It's a little bit painful but can save a lot of time if you only need to translate few things.

Andes answered 9/11, 2017 at 13:35 Comment(0)
P
4

You can use a script called UpdatStoryboardStrings for this!
Get it here: https://github.com/AppliedIS/iOSL10n
Intructions for use: http://blog.appliedis.com/2013/05/22/localization-of-an-xcode-ios-app-part-2/

Pagurian answered 24/2, 2014 at 16:15 Comment(2)
It's absolutely ridiculous an external tool has to be used for something that should be trivialWarta
dangerous script, it messed up my projectHaphazardly
B
2

With Xcode 6+, ideally developers should not have to manually manage strings files. Use XLIFF export to automatically gather development language strings to send to translators, and then use XLIFF import to update the strings files with translations.

https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html#//apple_ref/doc/uid/10000171i-CH5-SW9

Another option is to use ibtool --export-strings-file directly.

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ibtool.1.html

Bust answered 1/12, 2015 at 18:59 Comment(2)
i just removed label from my storyboard and export For Localization, removed label still present in .XLIFF file :(Collage
Yes but this solution is totally overkill and a big hassle for simple, 1-dev apps. The Localized files should really be updated automatically (they still aren't in Xcode 8).Sotos
A
0

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

Arcanum answered 1/9, 2019 at 16:33 Comment(0)
S
-1

Tested with Xcode 11, you can simply deselect the language. enter image description here

Do not delete the file on disk. enter image description here

And then choose to use the existing file. enter image description here

The old translations will be kept and the new keys will be added.

Shiverick answered 5/6, 2020 at 16:49 Comment(4)
how do get this second pop up?Greenlee
To get 2nd pop up just select the file again after unselect.Bushmaster
It does not add new keys.Sitsang
It doesn't add the new keys, it just uses back the old file without any changesRelinquish

© 2022 - 2024 — McMap. All rights reserved.