99 lines
2.7 KiB
Bash
Executable File
99 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -x
|
|
set -e
|
|
|
|
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
REPO_ROOT=$BIN_DIR/../..
|
|
LOCALIZATION_ROOT=$REPO_ROOT/Signal/translations
|
|
|
|
cd $LOCALIZATION_ROOT
|
|
|
|
# Pull all translations which are at least 80% complete
|
|
tx pull -a --minimum-perc=80
|
|
|
|
# Legacy hack: pull *any existing* translations regardless of their completion.
|
|
# Once supported, we don't want to drop any translations.
|
|
tx pull --force
|
|
|
|
# There's some problem with nb_NO, iconv fails to parse it.
|
|
# I'm guessing it some kind of unicode encoding issue.
|
|
rm -rf nb_NO.lproj
|
|
|
|
for dir in *.lproj
|
|
do
|
|
|
|
# en.lproj is already utf-8
|
|
if [[ "$dir" = "en.lproj" ]]; then
|
|
continue
|
|
fi
|
|
|
|
pushd $dir
|
|
|
|
translations=$(ls *.strings)
|
|
for translation in $translations; do
|
|
# Transifex pulls utf-16, but our string linting script needs utf-8.
|
|
# Plus we can see the string diffs in GH this way.
|
|
echo "Converting $dir/$translation to UTF-8"
|
|
iconv -f UTF-16 -t UTF-8 $translation > $translation.utf8
|
|
mv $translation.utf8 $translation
|
|
done
|
|
|
|
# missing translations in stringsdict files are not filled with the source language automatically
|
|
if [[ "$dir" == ??"_"* ]]; then
|
|
echo "skipping $dir/PluralAware.stringsdict right now"
|
|
else
|
|
swift $BIN_DIR/MergeStringsDictFiles.swift ../en.lproj/PluralAware.stringsdict PluralAware.stringsdict
|
|
fi
|
|
popd
|
|
|
|
done
|
|
|
|
for dir in ??_*.lproj
|
|
do
|
|
pushd $dir
|
|
lang=${dir:0:2}
|
|
|
|
# merge with "main" (country independent) version of the language
|
|
if [ -e ../$lang.lproj/PluralAware.stringsdict ]; then
|
|
swift $BIN_DIR/MergeStringsDictFiles.swift ../$lang.lproj/PluralAware.stringsdict PluralAware.stringsdict
|
|
else
|
|
swift $BIN_DIR/MergeStringsDictFiles.swift ../en.lproj/PluralAware.stringsdict PluralAware.stringsdict
|
|
fi
|
|
|
|
popd
|
|
|
|
done
|
|
|
|
# Parse the PluralAware.stringsdict files to ensure they're not malformed.
|
|
lang_errors=()
|
|
for dir in *.lproj
|
|
do
|
|
pushd "$dir"
|
|
if [ -e PluralAware.stringsdict ]; then
|
|
plutil PluralAware.stringsdict || lang_errors+=("$dir")
|
|
fi
|
|
popd
|
|
done
|
|
if [ "${#lang_errors[@]}" -gt 0 ]; then
|
|
1>&2 echo "Some languages have malformed .stringsdict files: ${lang_errors[*]}"
|
|
exit 1
|
|
fi
|
|
|
|
# Get and build iStringsCheck from https://github.com/signalapp/l10n_lint
|
|
# This does some checks to make sure all strings are present and that interpolated strings have the right number of arguments
|
|
LINT_CMD=$(command -v l10n_lint)
|
|
LINT_CMD=${LINT_CMD:-$REPO_ROOT/../l10n_lint/target/debug/l10n_lint}
|
|
|
|
if [ -e $LINT_CMD ]
|
|
then
|
|
$LINT_CMD en.lproj/Localizable.strings .
|
|
$LINT_CMD en.lproj/InfoPlist.strings .
|
|
else
|
|
echo "Missing string linter. See: https://github.com/signalapp/l10n_lint"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Make sure you register any new localizations in XCode! (Go to Project > Signal > Localizations > Add Localizations)"
|