Use single storyboard file for Base Internationalization in iOS 6 (2/2)
8. You got what you need, check attachments
9. Add Build Phase Run Script to update storyboards strings files auto
10. Create SingleStoryboardLocalize.py or .sh This script will do task as below(under construction):
Code:
#!/bin/sh
# Auto Create Locale Strings Script
# cls.sh
# Find .storyboard file inside project folder
for storyboardPath in `find . -name "*.storyboard" -print`
do
# Get storyboard file name
storyboardFile=$(basename "$storyboardPath")
# Get Base strings file path
baseStringsPath=$(echo "$storyboardPath" | sed 's/storyboard/strings/g')
# Get New Base strings file path
newBaseStringsPath=$(echo "$storyboardPath" | sed 's/\.storyboard/_new\.strings/g')
# Get strings file name
stringsFile=$(basename "$baseStringsPath")
#echo $stringsFile
echo Create $newBaseStringsPath from $storyboardFile
ibtool --export-strings-file $newBaseStringsPath $storyboardPath
# Convert UTF-16 to UTF-8
iconv -f UTF-16 -t UTF-8 $newBaseStringsPath > $baseStringsPath
rm $newBaseStringsPath
# Get all locale strings file path
for localeStringsPath in `find . -name "$stringsFile" -print`
do
if [ $baseStringsPath != $localeStringsPath ]
then
oldLocaleStringsPath=$(echo "$localeStringsPath" | sed 's/\.strings/_old\.strings/g')
cp $localeStringsPath $oldLocaleStringsPath
echo Merge $baseStringsPath to $localeStringsPath
awk 'NR==FNR&&/^\/\*/{x=$0;getline;a[x]=$0;next}/^\/\*/{x=$0;print;getline;$0=a[x]?a[x]:$0;printf $0"\n\n"}' $oldLocaleStringsPath $baseStringsPath > $localeStringsPath
rm $oldLocaleStringsPath
fi
done
done
10.1 Find Base.lproj folder in $(PROJECT_DIR)
10.2 Find all ??.lproj folders in $(PROJECT_DIR)
10.3 Find all .storyboard files in Base.lproj folder
10.4 use ibtool to create the newest storyboard strings files base on all .storyboard files and convert it to UTF-8 format
10.5 Merge the newest storybord strings files to all relevant localize strings files.
10.6 Delete the newest storyboard strings files.
I am not good at python, does anyone can do it for us?