How to assign location specific BundleDisplayNames for different Targets How to assign location specific BundleDisplayNames for different Targets swift swift

How to assign location specific BundleDisplayNames for different Targets


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.


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://stackoverflow.com/a/33749062/218152.

Specific localization to specific targets:

This is only useful if you want to explicitly control which languages go into which target. See https://stackoverflow.com/a/33791181/218152.