How to assign location specific BundleDisplayNames for different Targets
Asked Answered
L

2

8

I have 2 Apps : Free & Full I have 2 Languages : English & German

This results in 4 different App-Names

How can I achieve this.

Actually all my targets have the name "Free" in it, even it the the Full Version.

I know: I have 1 InfoPlist.strings File, which is multiplied by Localization and I can assign them to targets. So for 1 App I can localize the BundleDisplayName.

But how can I assign the specific names for the second app ?

Lozano answered 2/11, 2015 at 14:14 Comment(0)
M
2

PlistBuddy is your friend here. What you need to do is update your plist in a build time.

  1. You have to create custom scheme for every target you have (I assume you are already has that)
  2. In your xcode go to scheme and add post action like that to custom scheme target:

enter image description here

Here is the code:

infoplist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
/usr/libexec/PlistBuddy -c "Set CFBundleName some_new_name_here" "$infoplist"

Important thing with this approach is that you're not change nothing in your plist file but with post-actions you already changing the packet prepared for device, so you keep your code repository nice and clean.

Muns answered 12/11, 2015 at 14:42 Comment(2)
Thanks for helping. Is there really no other way to achieve this. This sounds to me more like a hack. I mean can't we do this with XCode out of the box ?Lozano
Hmmm, for German & English you have two plists localized, for Free and Premium you have plist buddy, what is official Apple tool also. I don't think if there is more "official" way to do this.Muns
R
1

Associate InfoPlist.strings to targets

From the Apple Developer Technical Notes:

If your app supports localization, be sure to localize CFBundleDisplayName by adding it to all your language-specific InfoPlist.strings files. Furthermore, be sure to use a name that complies with the App Review Guidelines for your app.

Prerequisites

  • I am assuming you already have multiple targets.

  • I am also assuming you already have an InfoPlist.strings file. If your do not, code > File > File... > Resource > Strings File > Next > Save As: InfoPlist > Base.lproj > Target: the english target > Create

  • Ensure you have enabled this in your Info.plist:

    <key>LSHasLocalizedDisplayName</key>
    <true/>
    

Step by step

  1. In Project Navigator, select InfoPlist.strings.
  2. In File Inspector > Localization, select all the languages. This will create and/or copy said InfoPlist.strings into their respective locations. Localize InfoPlist.strings
  3. Would you want to add languages, you achieve this in Project Navigator > project > Project & Target List > Project > Info > Localizations > +. Again, keep Use Base Internationalization.
  4. Unfortunately, when you execute step 2., Xcode does all the magic for you. It is worth noting that in versions of Xcode where that magic did not happen, you had to do the associations by hand. Step 5. is about reverting the magic.
  5. Remove InfoPlist.strings from the Project Navigator. Of course, only Remove References when prompted.
  6. In the Finder, locate en.lproj, drag it onto your Project Navigator, pick Create Groups, add to target your English, or Base target, Finish
  7. Repeat step 6 with de.lproj, fr.lproj, each time dragging the entire .lproj from the Finder, and associating with the appropriate target.
  8. Some .lproj may contain other localized files for which you want to enjoy the magic of step 3. Simply remove their references.
  9. You are done.

The final setup, for say the German language, will look like this in the File Inspector:

One InfoPlist.strings per target


References:

Share localization across targets:

This is the general method to achieving localization. See https://mcmap.net/q/931129/-different-storyboard-localization-per-target.

Specific localization to specific targets:

This is only useful if you want to explicitly control which languages go into which target. See https://mcmap.net/q/931129/-different-storyboard-localization-per-target.

Reductase answered 19/11, 2015 at 1:40 Comment(1)
Dear SwiftArchitect. Thank you very much for the explanation. This sounds very good and I will test this. Actually I have my own hack, which I am not happy with. So I will check this definitely in one of my next releases. Ill come back to this. Thanks a lot.Lozano

© 2022 - 2024 — McMap. All rights reserved.