How to make UILabel contents non localizible when genetating string via ibtool? - ios

I have some labels on my xib. Some of them are not need to be localized. When i generate strings file via ibtool all labels content included in result file.
How can i exclude some UI objects in IB from localization when generate strings?

Unfortunately there is no way to annotate the content of your nib/xib files so that ibtool's --export-strings-file command ignores certain strings.
You could instead opt to use the --export-xliff option and then edit the XLIFF file to lock segments that must not be translated (attribute translate="no") before sending them out to be localized in all your languages. That's probably only worth doing if the localizers use a XLIFF-compatible CAT tool though.

Related

NSLocalizedString in Spritekit SKLabelNode

I've been searching all over the internet and there doesn't seem to be a clear explanation on how to localize strings using SpriteKit. Only seeing tutorials for people using the interface builder, but all I really want is, imagine this:
I have an SKLabelNode called label. And I define the text like:
labl.text = NSLocalizedString("titleOfTheScreen",nil)
So basically what I think I have to do is add the new language in the Project settings. Then, I add a new Strings file called Localized, and add it to the new folder.
But what happens to my English language? There's no file for the original one
First you have to add a Strings File:
Then open the project settings and add a new language:
Mark your added strings file as target:
Find the newly added localising file. (English is automatically added)
From your screenshots I can see that you have "File.strings" file. You should have created "Localizable.strings" file.
Also, I can see that you have the (Base), (English) and (German) strings version. Why do you think English is not there?
In each of the files you should put strings like that:
"titleOfTheScreen" = "blah-blah";
Replace "blah-blah" with the proper translation in each of the strings files. It's important to note that the semi-colon at the end of the lines in strings files are mandatory, otherwise Xcode would issue some really funny error messages. This is easy to overlook if you're programming in Swift and trailing semi-colons are not mandatory.

Specify base localization for Localized formatted APNS strings

My base localizations are in storyboards, but also in a struct like this:
struct Strings {
struct Restaurant {
static let makeCall = NSLocalizedString("Restaurant-makeCall", value: "Call %#", comment: "Restaurant-makeCall: title for button that allows you to call a place")
}
//...many more
}
This works pretty well because it keeps them in one place, defines a key that is separate from the base translation value, and gives me autocomplete when I'm using them: Strings.Restaurant.makeCall
To enter translations, I use the xliff import/export process: editor > export for localization. I found genstrings had trouble with the longhand form of NSLocalizedString.
This all works well until I get to Localized APNS Messages. Given an loc-key and optional loc-args, They search for a matching localization key.
For the translations, this works, because there's a Localizable.strings built for each translation when I import the translated xliff file.
There is no Localizable.strings file for my base translation. I attempted to make one, but the xliff export does not notice those fields to add to other translations, so I think that's not the right way to do it.
How do I add base translations in a way that will work for APNS?
One functional, but duplicative approach is to define them in both places:
Define keys (and unused values) in the Strings struct. The xliff export notices these and this allows other languages to provide translations
Define keys and values in a Localizable.strings file you create for your base translation. This allows APNS to find the values when you're in the base language, but xliff export can't see these.
This works, but if somebody ever changes one without keeping the other file up-to-date, differences in translation will occur that will be hard to detect, so I don't like it very much.

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.
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
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.
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.
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).
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.

flag for no localization in iOS storyboard [duplicate]

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.
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
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.
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.
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).
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.

Automating UIStoryboard localizing without duplicating .storyboard files

So far, I used to manually create a localization file for storyboards texts, writing a line like this one for each UILabel / UIButton.-
"ACCESS" = "ACCESS";
and translated them with a similar function such as the proposed here.-
Storyboard/XIB and localization best practice
I've just found a nice tutorial to automate xibs and storyboards localization.-
http://kb.applingua.com/2011/10/extracting-and-localizing-xibs-ibtool/
which uses ibtool to automate the localization files creation (a huge step indeed), BUT needs to duplicate storyboard files to 'import' the new localized labels. I don't want to duplicate my storyboards and do any change twice from now on, but function on the first thread won't work with the automatically generated files, since the generated texts are like this.-
"Qa1-zu-aC4.normalTitle" = "ACCESS";
The first approach I can think of is manually updating the generated files (still, I'd save some time, but it'd be painful as well).
Is there any way to use the automatically generated files to translate the application on runtime without duplicating storyboards?
EDIT
Just found a workaround using regex to transform
"Qa1-zu-aC4.normalTitle" = "ACCESS";
into
"ACCESS" = "ACCESS";
The regex looks like this.-
Find "([^"]*)" = "([^"]*)";
Replace "\2" = "\2";

Resources