Localizing Info.plist variable with appended string
Asked Answered
H

1

9

I'm trying to localize the name of an app while still being able to append a string depending on the build configuration. So currently it is set up as:

<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}${BUNDLE_DISPLAY_NAME_SUFFIX}</string>

That setting is defined as:

Build Setting

This way we can add the suffix to the app for our different beta builds. The problem is that when we try to localize the app display name in the localized InfoPlist.strings like so

CFBundleDisplayName = "Localized App Name";

We overwrite the value stored in the Info.plist, and lose the suffix character. Is there any good way around this? We would like to avoid having multiple Info.plist files.

Hodgson answered 6/1, 2015 at 13:12 Comment(2)
How do you overwrite the value stored in the Info.plist? You do it manually?Shelburne
Can't comment because of lack of reputation, sorry. @Romain answer is correct but i spent all day to make it work. The thing is put script AFTER Compile Sources phase and Copy Bundle Resources phase. Hope it gonna help someone.Snorter
S
12

You will need a custom script to do this. Here is one that is working for me

PREFIX_IDENTIFIER="=com.mycompany.bundlenameprefix="
PREFIX=""

if [ $CONFIGURATION == "Debug" ]
then
    PREFIX="α "
fi

if [ $CONFIGURATION == "Enterprise" ]
then
    PREFIX="β "
fi

for i in `dirname "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"`/*.lproj/InfoPlist.strings
do
    plutil -convert json "$i"
    sed -i -e "s/${PREFIX_IDENTIFIER}/${PREFIX}/g" "$i"
    plutil -convert binary1 "$i"
done

Then in your InfoPlist.strings add a prefix to the bundle name like so

CFBundleDisplayName = "=com.mycompany.bundlenameprefix=My App";
Shaman answered 11/1, 2015 at 11:6 Comment(1)
Great answer. A note for anyone troubleshooting this, if your target build directory has spaces in it you need to enclose the output of dirname in quotesEctoenzyme

© 2022 - 2024 — McMap. All rights reserved.