Xcode - Target specific localization
Asked Answered
S

3

9

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.

Stepdame answered 7/12, 2017 at 9:59 Comment(1)
This should help : #10524292Jejunum
S
5

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

Stepdame answered 7/12, 2017 at 12:42 Comment(2)
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.Pollie
Will this not still lead to all languages showing up on AppStore? Even for targets that doesn't use a specific language.Uneducated
M
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

Marxist answered 7/12, 2017 at 10:13 Comment(3)
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?Adapa
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)Marxist
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.Adapa
S
5

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

Stepdame answered 7/12, 2017 at 12:42 Comment(2)
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.Pollie
Will this not still lead to all languages showing up on AppStore? Even for targets that doesn't use a specific language.Uneducated
M
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

Misconstrue answered 3/7, 2022 at 5:4 Comment(1)
After doing this my app will NOT default to one of the remaining languages. Instead it just shows my "keys".Laurenlaurena

© 2022 - 2024 — McMap. All rights reserved.