This is ideally what I'd like to do:
- Set up a project in Xcode using a base localization of English. Ultimately I want English and let's say Dutch versions of my
Localizable.strings
and Storyboards - Externalise strings in code with
NSLocalizedString
, using keys of the formfooViewController.barLabel
, being diligent and adding proper context comments with every key - Add a Dutch localization to my Storyboard files
- Mark particular labels in the Storyboard as placeholders that will be set at runtime and do not require translations
- Add comments for labels in the Storyboard which do require translation
- Export the "development language"
xliff
file (Click on Project, Editor/Export For Localization..., choose "Development Language Only") - Open the English
xliff
file in a tool like Counterparts or Xliffie or even something web based - Add actual English translations alongside the
fooViewController.barLabel
keys, and re-save the en.xliff - Create an
nl.xliff
file from the originalen.xliff
and add Dutch translations - Import both
xliff
files into Xcode and have it create the appropriate.strings
files for both Dutch and English, for both the keys defined in code and those in the Storyboard; commit the new.strings
files into my source repository - At some future point after keys have been added, removed and changed in my source and Storyboards, export the "Development language"
en.xliff
again as the source of truth - Update the
en.xliff
andnl.xliff
files with current translations, having a tool highlight which keys had been added or removed - Import those
xliff
files back into Xcode which updates the.strings
files I can then check back in to my source repository
Does this make sense? Is this a reasonable thing to want to do? I think so, but it doesn't work.
Here are the problems I ran into:
- Xcode does not support step 4—the
xliff
format can mark a key astranslate=no
, but there is no way to annotate that in Xcode (ideally, Xcode wouldn't export keys marked as placeholders at all.) - Xcode does not support step 5—there is no way to set a translator comment for a label. There's not even a way to set the key independent of the placeholder text you put in the label on the Storyboard, which is a massive pain if you find filling labels with Lorem Ipsum useful when laying out your views.
- When you get to step 10, Xcode complains there is no target language specified in the
en.xliff
file. There is a way to change the target language (or, at least, create a new file with the target language set toEN
) in Counterparts but I couldn't find any way to do this with Xliffie. - Upon attempting to re-export the
en.xliff
file with updated keys, Xcode told me"Localization failed reading "[...]/Supporting Files/en.lproj/Localizable.strings, Please address the issue at file location 782"
at which character location I found... an apostrophe. Xcode can't export anxliff
file if the source.strings
file contains an apostrophe. What in the actual F...?! - Step 12 and 13 got weird, and I just don't understand what was happening. Both Counterparts and Xliffie had replaced my original
fooViewController.barLabel
keys with the English translations and looked like they were trying to tell me I had no English translations. Upon attempting to import theen.xliff
back into Xcode it told me I had no translations for all but the new keys and when I went ahead, it wiped the existing translations from theen.lproj/Localization.strings
file.
This is a mess.
Translating labels in Storyboards without being able to manually set their keys, add translator comments or mark particular labels as placeholders not-for-translation just doesn't work. We've resorted to connecting every label to an @IBOutlet
and setting its translation in viewDidLoad()
with NSLocalizedString
.
Xcode choking when it attempts to export a .strings
file containing an apostrophe beggars belief.
It also seems there's an underlying assumption that if the "development language" in Xcode is English, then the developers are in charge of the English translation. I can imagine no context outside that of a single-person indie developer shop where this is true.
Finally, it also seems I'm missing something about how the tools I've attempted to use structure their workflows. If anyone could enlighten me I'd be quite grateful.
Has anyone managed to construct a workable localization workflow where the developers aren't charged with ultimate editing control over the "development language" and the .strings
files checked into the repository are the source of truth?