From 66a905f1d6aa64899c5e4f6a66f020faffab0571 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Sun, 11 Dec 2022 11:05:05 -0800 Subject: [PATCH] Script for updating translations (#1030) Script for updating translation strings and print stats --- python/web/README.md | 6 ++++-- python/web/translation_update.sh | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 python/web/translation_update.sh diff --git a/python/web/README.md b/python/web/README.md index 55f1404e..69a4df71 100644 --- a/python/web/README.md +++ b/python/web/README.md @@ -73,12 +73,14 @@ When adding a localization for a new language, initialize the directory structur $ pybabel init -i messages.pot -d src/translations -l xx ``` -### Update an existing loclization +### Update an existing localization + +Tip: Use the script **translation_update.sh** in this dir to automatically extract strings, update existing localizations, and print translation statistics. After strings have been added or changed in the code, update the existing localizations. ``` -pybabel update -i messages.pot -d src/translations +$ pybabel update -i messages.pot -d src/translations ``` Then edit the updated messages.po file for your language. Make sure to update fuzzy strings and translate new ones. diff --git a/python/web/translation_update.sh b/python/web/translation_update.sh new file mode 100755 index 00000000..fa448862 --- /dev/null +++ b/python/web/translation_update.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +cd "$(dirname "$0")" +# Check for the existence of a python venv in the current dir +if ! test -e venv; then + echo "No python venv detected. Please run start.sh first." + exit 1 +fi + +source venv/bin/activate + +pybabel extract -F babel.cfg -o messages.pot . +pybabel update -i messages.pot -d src/translations + +echo +echo "Translation stats:" +find . -name \*.po -print -execdir msgfmt --statistics messages.po \;