Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 822
Gianni Costanzi Avatar asked Jan 02 '14 23:01

Gianni Costanzi


People also ask

How does NSLocalizedString work?

NSLocalizedString is a Foundation macro that returns a localized version of a string. It has two arguments: key , which uniquely identifies the string to be localized, and comment , a string that is used to provide sufficient context for accurate translation.


2 Answers

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

like image 184
Jeehut Avatar answered Sep 28 '22 08:09

Jeehut


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.

like image 43
Rahav Avatar answered Sep 28 '22 10:09

Rahav