Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...