Export For Localization with multiple targets

I have multiple targets in my app: targetA and targetB. Whenever i "Export For Localization", the .xliff generated will cointain translations for:


1) Main.storyboard

2) targetA/InfoPlist.strings

3) targetB/InfoPlist.strings

4) targetA/Localizable.strings

5) targetB/Localizable.strings


I want to avoid multiple Localizable.strings, and multiple InfoPlist.strings. We do not need one localization per target.


Any way i can force the "Export For Localization", to create a .xliff that only contains one Localizable.strings and one InfoPlist.strings?

Replies

I’d like to clarify your setup here. As a starting point, let’s consider your

InfoPlist.strings
file. Based on your post I believe you have one
InfoPlist.strings
that’s a member of both targetA and targetB. Is that right?

Is that true for every localised resource? Or just some subset?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks a lot for replying.


Yes, I have two Info.plist, one per target.

I have only one storyboard. The storyboard is memeber of both targetA and targetB.


I want to avoid multiple Localizable.strings, there are being created two(one per target)


Any way i can force the "Export For Localization", to create a .xliff that only contains one Localizable.strings?

What version of Xcode are you testing this with? I used Xcode 10.1 to create a project that has two targets, and then added a

Common
directory containing a
Localizable.strings
. The exported
en.xcloc
looks like this
en.xcloc
en.xcloc/Localized Contents
en.xcloc/Localized Contents/en.xliff
en.xcloc/Notes
en.xcloc/contents.json
en.xcloc/Source Contents
en.xcloc/Source Contents/TargetA
en.xcloc/Source Contents/TargetA/en.lproj
en.xcloc/Source Contents/TargetA/en.lproj/InfoPlist.strings
en.xcloc/Source Contents/TargetA/Base.lproj
en.xcloc/Source Contents/TargetA/Base.lproj/LaunchScreen.storyboard
en.xcloc/Source Contents/TargetA/Base.lproj/Main.storyboard
en.xcloc/Source Contents/TargetB
en.xcloc/Source Contents/TargetB/en.lproj
en.xcloc/Source Contents/TargetB/en.lproj/InfoPlist.strings
en.xcloc/Source Contents/TargetB/Base.lproj
en.xcloc/Source Contents/TargetB/Base.lproj/LaunchScreen.storyboard
en.xcloc/Source Contents/TargetB/Base.lproj/Main.storyboard
en.xcloc/Source Contents/Common
en.xcloc/Source Contents/Common/en.lproj
en.xcloc/Source Contents/Common/en.lproj/Localizable.strings

As you can see, there’s only one copy of

Localizable.strings
is the
Source Contents
directory. More to the point, the string I put in
Localizable.strings
only shows up once in the
en.xliff
.
$ grep aaa en.xcloc/Localized\ Contents/en.xliff 
<trans-unit id="aaa">

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I got the same directory structure.

The issue is when you open en.xliff. Inside the xliff, is gonna ask for two translations for Localizable.strings.

However, our grep commands return different results!!!


$ grep hi fr.xliff

<trans-unit id="hi">
     <source>hi</source>
<trans-unit id="hi">
     <source>hi</source>


What can we have different? I duplicated the first target, see my project: https://github.com/albertomota-codes/LocalizationTargets

Thanks for posting the test project. That allowed me to see what’s different between your case and mine. In your case you have Export For Localization generated the

Localizable.strings
file on the fly from your various calls to
NSLocalizedString
. In my case I added
Localizable.strings
as its own file in my target. If I add such a file to your project and then include it in both targets, the resulting
fr.xliff
file only contains a single instance of strings therein.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Eskimo, thanks a lot! Now it makes sense. However, i am not able to reproduce: "If I add such a file to your project and then include it in both targets, the resulting fr.xliff file only contains a single instance of strings " How do you add such file? How do you include it in both targets? I have tried by creating a new file using Xcode and adding it to the both targets at the creation without success. I have tried by creating a new file using third-party text processor, then add it to the project and to both targets at the same time without success. Thanks for your help!

I can’t recall exactly what I did (it’s been a few weeks) but I don’t think I did anything special. It was probably New > File > Strings File followed by tweaking the target inclusion and localisations using the File Inspector.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
In my existing project, I tried to remove the target-independent strings files and share the same one among targets. However, by exporting localisation it still results in two files based on the two targets?

Is there a guideline or tutorial somewhere to show the proper setup?

Exporting localizations is a mess and doesn't work for complex projects with many targets. For one thing targets which build both for RELEASE and DEBUG fail when I look at the report navigator for exporting localizations.