Marking some XIB/Storyboard strings as not localizable
Asked Answered
D

3

17

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.

Dinka answered 10/12, 2014 at 17:32 Comment(1)
It looks like this isn't possible. I filed a radar (19232051) in case someone comes across this question in the future and wants to see if it got implemented.Dinka
A
4

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.

Anson answered 16/2, 2016 at 23:38 Comment(2)
BartyCrouch rules!Whelm
@Whelm If you liked BartyCrouch, you might want to also checkout ReMafoX, its successor with a GUI and many other improvements over BartyCrouch: remafox.appAnson
C
8

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 
Coronograph answered 28/10, 2017 at 15:33 Comment(2)
What do you mean with 'Comment for Localizer' field? Is that a field in XCode? Can't find it.Stumble
NVM, it's in the document section of a object. Works great!Stumble
E
5

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.

Excitant answered 9/9, 2017 at 19:41 Comment(1)
This doesn't cover some cases like, for example, navigation item text, as there is no option to set the type to "Attributed" from the Attributes inspector.Unconcerned
A
4

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.

Anson answered 16/2, 2016 at 23:38 Comment(2)
BartyCrouch rules!Whelm
@Whelm If you liked BartyCrouch, you might want to also checkout ReMafoX, its successor with a GUI and many other improvements over BartyCrouch: remafox.appAnson

© 2022 - 2024 — McMap. All rights reserved.