weblate/scripts/update-locales
2021-03-23 13:56:36 +01:00

70 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
# Renerates .po files used for translating Weblate
# Exit on failure
set -e
. scripts/test-database
version=$(python -c 'import weblate.utils.version; print(weblate.utils.version.VERSION_BASE)')
COMPONENTS="weblate/application weblate/javascript weblate/documentation"
do_wlc() {
for component in $COMPONENTS ; do
wlc $1 $component
done
}
# Lock Weblate
do_wlc lock
# Push changes from Weblate to GitHub
do_wlc push
# Update Weblate remote
git remote update weblate
# Pull changes from GitHub
git rebase --onto weblate/main
# Cleanup locale dirs
find weblate/locale -name '*.mo' -o -name '*~' -delete
find weblate/locale -type d -empty -delete
# Update po files itself
./manage.py makemessages --keep-pot -a -i 'data/*' -i 'docs/*' -i 'examples/*' -i 'build/*'
./manage.py makemessages --keep-pot -a -i 'data/*' -i 'docs/*' -i 'examples/*' -i 'build/*' -d djangojs
# Fix Report-Msgid-Bugs-To as it gets removed
sed \
-i \
-e 's@"Report-Msgid-Bugs-To:.*@"Report-Msgid-Bugs-To: https://github.com/WeblateOrg/weblate/issues\\n"@' \
-e 's/"Project-Id-Version:.*/"Project-Id-Version: Weblate '$version'\\n"/' \
weblate/locale/*/*/*.po weblate/locale/*.pot
# Include translations from Django
for locale in weblate/locale/*/LC_MESSAGES/django.po ; do
code=${locale#weblate/locale/}
code=${code%/LC_MESSAGES/django.po}
file=~/work/django/django/conf/locale/$code/LC_MESSAGES/django.po
if [ -f $file ] ; then
msgmerge --previous -C $file -U $locale weblate/locale/django.pot
fi
done
# Update PO files for documentation
make -C docs update-po
# Commit changes
git add $(find weblate/locale/ docs/locales/ -name '*.po' -o -name '*.pot')
git commit -n -m "i18n: Update PO files"
# Push changes
git push
# Unlock Weblate
do_wlc unlock