Last active
June 9, 2016 19:37
-
-
Save tritter/6a959b0c0b4a415e108f034ea8c62d33 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: "note_location_disclaimer" = "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: | |
# localizable_keys=("NSLocationWhenInUseUsageDescription=note_location_disclaimer") | |
localizable_keys=("NSLocationWhenInUseUsageDescription=note_location_disclaimer") | |
# Remove old InfoPlist.strings | |
find . -name "*InfoPlist.strings" -delete | |
| |
# 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 key_value in ${localizable_keys[@]} | |
do | |
# define keys of arrays using the same index | |
l_key="${key_value##*=}" | |
i_p_key="${key_value%%=*}" | |
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 -n "s/\"${l_key}\" *\([^ ]*\) */\"${i_p_key}\"\1/p" $file >> "${file_dir}/InfoPlist.strings" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment