Ido Nave
Ido Nave

Reputation: 261

Xcode - Target specific localization

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.

Upvotes: 9

Views: 5817

Answers (3)

Sreekuttan
Sreekuttan

Reputation: 1954

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

Upvotes: 2

Ido Nave
Ido Nave

Reputation: 261

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

Upvotes: 5

Yitzchak
Yitzchak

Reputation: 3416

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

Upvotes: 5

Related Questions