|
| 1 | +#!/bin/bash |
| 2 | +TARGETS="Signal/src Pods/SignalServiceKit Pods/JSQMessagesViewController" |
| 3 | +TMP="$(mktemp -d)" |
| 4 | +STRINGFILE="Signal/translations/en.lproj/Localizable.strings" |
| 5 | + |
| 6 | +# Make sure we are in the right place |
| 7 | +if [ ! -d "Signal/src" ]; then |
| 8 | + echo "Please run this tool from the repository's base directory" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +# Search directories for .m & .h files and collect string definitions with genstrings |
| 13 | +find $TARGETS -name "*.m" -print0 -name "*.h" -print0 | xargs -0 genstrings -o $TMP |
| 14 | + |
| 15 | +# We have to convert the old and new .strings files to UTF-8 in order to deal with them |
| 16 | +OLDUTF8=$(iconv -f UTF-16 -t UTF-8 $STRINGFILE) |
| 17 | +NEWUTF8=$(iconv -f UTF-16 -t UTF-8 $TMP/Localizable.strings) |
| 18 | + |
| 19 | +# Let's merge the old with the new .strings file: |
| 20 | +# 1. Select old string definition lines |
| 21 | +# 2. Setup field separators |
| 22 | +# 3. Read old string definitions as associative array |
| 23 | +# 4. In new file, if possible, insert old definition |
| 24 | +# 5. Add separator and semicolon only for string definition lines |
| 25 | +# 6. Convert output back to UTF-16 to final location |
| 26 | +echo "$OLDUTF8" | grep -Eo '^".*"' | \ |
| 27 | + awk 'BEGIN {FS = "[ ]*=[ ]*"; OFS = ""} \ |
| 28 | + NR == FNR {a[$1] = $2; next} \ |
| 29 | + {$2 = ($1 in a ? a[$1] : $2); \ |
| 30 | + if($2 ~ /"[;]*$/){$2 = " = "$2}; \ |
| 31 | + if($2 ~ /"$/){$2 = $2";"}; \ |
| 32 | + print}' - <(echo "$NEWUTF8") | \ |
| 33 | + iconv -f UTF-8 -t UTF-16 > $STRINGFILE |
0 commit comments