mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.4 KiB
Bash
79 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
REPO_ROOT=$BIN_DIR/../../..
|
|
cd $REPO_ROOT
|
|
|
|
SSK_DIR="../SignalServiceKit/src"
|
|
|
|
pushd $SSK_DIR
|
|
CURRENT_SSK_BRANCH=$(git status|awk 'NR==1{print $3}')
|
|
if [ $CURRENT_SSK_BRANCH != "master" ]
|
|
then
|
|
if [[ $* == *--non-master* ]]
|
|
then
|
|
echo "[!] Note - generating from non-master SSK."
|
|
else
|
|
echo "[!] Error - SSK must be on master to be sure we're generating up-to-date strings, or use '--non-master'."
|
|
exit 1
|
|
fi
|
|
fi
|
|
popd
|
|
|
|
TARGETS="Signal/src ${SSK_DIR}"
|
|
TMP="$(mktemp -d)"
|
|
STRINGFILE="Signal/translations/en.lproj/Localizable.strings"
|
|
|
|
for TARGET_DIR in $TARGETS
|
|
do
|
|
|
|
if [ ! -d $TARGET_DIR ]; then
|
|
echo "Unable to find required directory: ${TARGET_DIR}."
|
|
exit 1
|
|
fi
|
|
|
|
done
|
|
|
|
# Search directories for .m & .h files and collect string definitions with genstrings
|
|
find $TARGETS -name "*.m" -print0 -o -name "*.h" -print0 -o -name "*.swift" -print0 | xargs -0 genstrings -o $TMP
|
|
|
|
# We have to convert the new .strings files to UTF-8 in order to deal with them
|
|
# STRINGFILE is already UTF-8.
|
|
OLDUTF8=$(cat $STRINGFILE)
|
|
NEWUTF8=$(iconv -f UTF-16 -t UTF-8 $TMP/Localizable.strings)
|
|
|
|
# Let's merge the old with the new .strings file:
|
|
# 1. Select old string definition lines
|
|
# 2. Setup field separators
|
|
# 3. Read old string definitions as associative array
|
|
# 4. In new file, if possible, insert old definition
|
|
# 5. Add separator and semicolon only for string definition lines
|
|
# 6. Convert output back to UTF-16 to final location
|
|
echo "$OLDUTF8" | grep -Eo '^".*"' | \
|
|
awk 'BEGIN {FS = "[ ]*=[ ]*"; OFS = ""} \
|
|
NR == FNR {a[$1] = $2; next} \
|
|
{$2 = ($1 in a ? a[$1] : $2); \
|
|
if($2 ~ /"[;]*$/){$2 = " = "$2}; \
|
|
if($2 ~ /"$/){$2 = $2";"}; \
|
|
print}' - <(echo "$NEWUTF8") > $STRINGFILE
|
|
|
|
# Copy in strings from JSQMessagesViewController
|
|
#
|
|
# We have a wider array of translators than JSQ, and it's easier for our
|
|
# translators to translate for us directly rather than to direct them to the
|
|
# now defunct JSQMessagesView project.
|
|
|
|
echo "Copying strings from JSQMessagesViewController"
|
|
JSQ_STRINGS_PATH="../JSQMessagesViewController/JSQMessagesViewController/Assets/JSQMessagesAssets.bundle/Base.lproj/JSQMessages.strings"
|
|
if [ ! -f $JSQ_STRINGS_PATH ]; then
|
|
echo "[!] Error. Expected to find strings for JSQMessagesViewController at ${JSQ_STRINGS_PATH}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "
|
|
// Strings Copied in from JSQMessagesViewController" >> $STRINGFILE
|
|
cat $JSQ_STRINGS_PATH | grep -v "^//" >> $STRINGFILE
|
|
|