Lou Franco
Lou Franco

Reputation: 89172

Marking some XIB/Storyboard strings as not localizable

I am using Base Internationalization for XIB/Storyboard files and the "Export for Localization" method using XLIFF files for translators.

I have some labels, buttons, etc. that have text that should be translated, but I also have labels where we use some placeholder text (like a full-name) so you can see what the view would look like when populated with data, but those labels always have their text come from an outlet programmatically.

Is there some way to mark this label's .text property that is set in the XIB as non-localizable so that it doesn't end up in the XLIFF (or resulting .strings) files.

I know that I can remove the text -- I also thought about having a prefix (like @"!DNL!") to mean that the translator shouldn't localize, but I am hoping that there is just a standard way to do this.

Upvotes: 17

Views: 2425

Answers (3)

Cihat Gündüz
Cihat Gündüz

Reputation: 21468

UPDATE:

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.

To ignore specific Strings, simply add one of the customizable ignore flags from the "Interface Builder" pane in the "Comment for Localizer" field in your Storyboard/XIB files and the build-script you configured following the above linked video will exclude it on next build of your project (or press of the "Update" button in the config).

Config Option, Interface Builder pane


OLD ANSWER:

This is now possible using the BartyCrouch command line utility which I recently wrote to solve this problem (see installation instructions in my answer on that thread).

BartyCrouch runs ibtool for you and does additional processing on top of its resulting .strings file. It will exclude views from translation if you include #bc-ignore! into your value or comment within your base internationalized Storyboard/XIB file.

Please check out out the related section within the README on GitHub for detailed information.

Upvotes: 4

Chris Vasselli
Chris Vasselli

Reputation: 13334

I add a note "DNL" to the "Comment for Localizer" field in the identity tab. Then, I run this command to automatically remove all of those elements from the XLIFF:

xmlstarlet ed -d "//*[contains(text(), 'Note = \"DNL\"')]/.." en.xliff > out.xliff

Basically, it's using xmlstarlet (which can be downloaded via homebrew) to find all elements that contain the text Note = "DNL", and then deleting the parent of that element from the XLIFF.

Combined with using xcodebuild -exportLocalizations, you can make a pretty simple script for generating your XLIFFs:

xcodebuild -exportLocalizations -localizationPath build -project ProjectName.xcodeproj
xmlstarlet ed -d "//*[contains(text(), 'Note = \"DNL\"')]/.." build/en.xliff > build/out.xliff 

Upvotes: 8

Wouter
Wouter

Reputation: 1568

It turns out the localization export from Xcode ignores attributed strings in the storyboard.

So just set the type of text for every label/button you want to exclude to Attributed in the Attributes Inspector.

enter image description here

This will give you an attributed string rather than a plain string, which as far as I know has no implications, apart from the (empty) list of attributes that has to be kept in memory now.

Upvotes: 5

Related Questions