weblate/scripts/update-locales
Michal Čihař 4316b6467f chore: introduce shellfmt for formatting shell files
This makes them look consistent and formatting is now enforced.
2024-10-04 15:03:44 +02:00

88 lines
2.5 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Renerates .po files used for translating Weblate
# Exit on failure
set -e
. scripts/test-database.sh
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
# 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
# Update headers
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"/' \
-e 's/SOME DESCRIPTIVE TITLE./Weblate localization./' \
-e '/^# FIRST AUTHOR/ D' \
-e "/^# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER/ D" \
-e "/^# Copyright (C) [0-9 -]* Michal Čihař/ D" \
-e "/^# This file is distributed under the same license as the/ D" \
weblate/locale/*/*/*.po weblate/locale/*.pot \
docs/locales/docs.pot docs/locales/*/LC_MESSAGES/docs.po
# Ensure licensing information is in place
scripts/reuse-annotate \
weblate/locale/*.pot \
docs/locales/docs.pot
scripts/reuse-annotate \
--skip-existing \
weblate/locale/*/*/*.po \
docs/locales/*/LC_MESSAGES/docs.po
# Commit changes
# shellcheck disable=SC2046
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