8

My project includes several targets, each target is used for a different customer. Some customers need specific localization, and I don't want all the customers to get this specific localization. Since localization is handled on the project level, I couldn't find a way to add localization only for a specific target.

Any suggestions how to do it?

Looking for stable option without the need to delete unused localization before each build.

thedp
  • 8,350
  • 16
  • 53
  • 95
Ido Nave
  • 231
  • 3
  • 11
  • This should help : https://stackoverflow.com/questions/10523792/localized-project-with-several-targets-with-localized-app-names – Nitish Dec 07 '17 at 10:08

3 Answers3

5

Create a separate "Localizeable.strings" for each target.

link the correct strings files with each "group" of strings.

Then set it in the Build Phases for each target the correct "strings" like this:

Setting Localizable resource for target

Yitzchak
  • 3,303
  • 3
  • 30
  • 50
  • If I've got multiple targets, do I need to have a `Localizable.strings` file for each target or can I get away with adding one for just the targets I need to localize? – Adrian Aug 19 '19 at 03:53
  • Hello @Adrian, Each localizable.strings is just a regular file. in the right pane (for any file) you select the targets that needs that file (under "target membership"). each file can be attached to several targets. (the same relevant for code too) – Yitzchak Aug 19 '19 at 04:14
  • I just powered down, but I’ll fiddle with it in the morning. Every f***ing thing I’ve tried from WWDC videos on down assumes a dirt simple app with one target and nothing has worked. Thank you for getting back so quickly. – Adrian Aug 19 '19 at 04:19
3

I manage to solve it with @Yitzchak answer + additional changes:

  • In project level add the desired language.
  • Remove original localizable file from the target.
  • Create new Localizable.strings / InfoPlist.strings and add it to the target.
  • Select only the relevant languages in "localization" option (see the image below)

enter image description here

enter image description here

Ido Nave
  • 231
  • 3
  • 11
  • One recommendation to the above solution though.. we don't need to remove original Localization file(will be helpful if there are plenty of them), just uncheck whichever targets are not needed for existing files under "Target Membership" section. and when adding new files just select the remaining Targets. – Trident May 29 '20 at 00:29
  • Will this not still lead to all languages showing up on AppStore? Even for targets that doesn't use a specific language. – Joel Rudsberg Feb 16 '21 at 17:50
2

Use the Build phase script to remove unwanted languages from specific targets. This will not appear in removed languages in the application or Appstore.

select YOUR TARGET goto Build Phase click the '+' on the left top then choose New Run Script Phase then add the following script.

# add language code to remove it during build.
for lang in "hi" "fr"
do
    if [ -e "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/$lang.lproj" ]; then
        rm -r "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/$lang.lproj"
    else
        echo "file does not exists"
    fi
done

You can add language codes of languages that you want to remove from your target. The remaining localizations from your PROJECT will reflect in your build.

enter image description here

Sreekuttan
  • 1,579
  • 13
  • 19