Skip to content

Instantly share code, notes, and snippets.

@txomon
Forked from tritter/createInfoPlistStrings.sh
Last active June 9, 2016 19:13
Show Gist options
  • Save txomon/c1cb97d705557fa5facc32142bc8de1c to your computer and use it in GitHub Desktop.
Save txomon/c1cb97d705557fa5facc32142bc8de1c to your computer and use it in GitHub Desktop.
script is intended to use inside an Xcode project's build steps. It creates a InfoPlist.strings file that are used by the system to localize Info.plist values.
#!/bin/bash
# Thom Ritterfeld 2016
# This script is intended to use inside an Xcode project's build steps. It creates a InfoPlist.strings file that are used by the system to localize Info.plist values.
# Define localize keys values, the values are the ones that need to be placed inside InfoPlist.strings.
# For example in Localizable.strings you defined: "location_in_use_desc" = "we want to know where you work";
# This script will add "NSLocationWhenInUseUsageDescription" = "we want to know where you work"; into InfoPlist.strings.
# To define these keys define the key of Localizable.strings into localizable_keys and the key for InfoPlist.strings into info_plist_keys.
# Use the same positions, because of lack of good dictionary support. For the sample:
# declare -a localizable_keys=("location_in_use_desc")
# declare -a info_plist_keys=("NSLocationWhenInUseUsageDescription")
localizable_keys=("location_in_use_desc")
info_plist_keys=("NSLocationWhenInUseUsageDescription")
# Remove old InfoPlist.strings
find -name InfoPlist.strings | xargs rm
# Find all Localization files
for file in $(find . -name "*.strings")
do
file_dir=$(dirname "${file}")
echo "Found strings file: ${file} for language $(basename $file_dir)"
# Loop through all localizable_keys with index
for index in ${!localizable_keys[*]}
do
# define keys of arrays using the same index
l_key=${localizable_keys[$index]}
i_p_key=${info_plist_keys[$index]}
echo "Value of ${l_key} of ${file} into ${i_p_key} in file ${file_dir}/InfoPlist.strings"
# search for keys | print the info_plist_key with the value of the Localization.strings | >> place into InfoPlist.strings file
sed -ne "s/${l_key}/$i_p_key/p" $file
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment