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?

Gianni Costanzi
  • 6,054
  • 11
  • 48
  • 74
  • 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. – Dinakar Feb 06 '14 at 03:01
  • 3
    Look at answer to this SO question: http://stackoverflow.com/questions/15094259/is-it-possible-to-update-a-localized-storyboards-strings – Miroslav Hrivik Apr 09 '14 at 12:24
  • I posted a clean solution to this problem here: http://stackoverflow.com/a/35398661/3451975 – Jeehut Feb 14 '16 at 23:31

8 Answers8

21

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.

Jeehut
  • 20,202
  • 8
  • 59
  • 80
  • Nice Work Dschee, you BartyCrouch solution seems to work great! – scrafy May 07 '16 at 14:05
  • 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. – Can Poyrazoğlu Dec 27 '16 at 15:47
  • @CanPoyrazoğlu Thanks for reporting this. Could you please make sure you're not running into [this issue](https://github.com/Flinesoft/BartyCrouch/issues/12)? 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). – Jeehut Dec 27 '16 at 16:49
  • @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. – Can Poyrazoğlu Dec 28 '16 at 10:29
  • Please also note that there is [this issue](https://github.com/Flinesoft/BartyCrouch/issues/36) 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. – Jeehut Dec 30 '16 at 09:00
  • Biggest problem of bartycrouch right now for me is the installation for xcode 7 – thibaut noah Feb 23 '17 at 13:42
  • @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. – Jeehut Mar 07 '17 at 08:48
  • @thibautnoah One more idea I have is: You can fork https://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 /bartycrouch` and `brew install /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. – Jeehut Mar 07 '17 at 08:53
  • 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. – Xvolks Apr 12 '17 at 22:22
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.

Rahav
  • 1,755
  • 15
  • 18
  • 17
    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 storyboard – user023 Apr 15 '15 at 10:26
  • 1
    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. –  Jun 01 '17 at 09:21
  • @user023 have you find something? – Er. Khatri Jun 03 '17 at 04:54
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.

Community
  • 1
  • 1
olik79
  • 1,402
  • 1
  • 13
  • 16
  • 1
    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. – hokkuk Jan 07 '15 at 00:42
  • 1
    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. – hokkuk Jan 07 '15 at 00:50
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.

tryp
  • 1,120
  • 20
  • 26
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/

Trond
  • 41
  • 6
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

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
  • i just removed label from my storyboard and export For Localization, removed label still present in .XLIFF file :( – Roman Simenok Oct 20 '16 at 13:11
  • 3
    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). – Guillaume Laurent Jan 05 '17 at 16:48
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

Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32
-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.

Foti Dim
  • 1,303
  • 13
  • 19