From 547e8a70234c93e35d8a4a0caf88ad598dfca743 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Wed, 11 Mar 2015 18:21:59 +0100 Subject: [PATCH] Add script that handles i18n operations init, extract and update can be done for all plugins at once --- babel-js.cfg | 7 +++++++ babel.cfg | 10 ++++++++++ manage-i18n.sh | 39 +++++++++++++++++++++++++++++++++++++++ run-tests.sh | 0 4 files changed, 56 insertions(+) create mode 100644 babel-js.cfg create mode 100644 babel.cfg create mode 100755 manage-i18n.sh mode change 100644 => 100755 run-tests.sh diff --git a/babel-js.cfg b/babel-js.cfg new file mode 100644 index 0000000..b25ae84 --- /dev/null +++ b/babel-js.cfg @@ -0,0 +1,7 @@ +[javascript: static/**.js] +encoding = utf-8 +domain = messages-js + +[javascript: templates/**.html] +encoding = utf-8 +domain = messages-js diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 0000000..9ef0fdd --- /dev/null +++ b/babel.cfg @@ -0,0 +1,10 @@ +[python: **.py] +encoding = utf-8 + +[jinja2: templates/**.txt] +encoding = utf-8 +extensions = jinja2.ext.autoescape, jinja2.ext.with_ + +[jinja2: templates/**.html] +encoding = utf-8 +extensions = jinja2.ext.autoescape, jinja2.ext.with_ diff --git a/manage-i18n.sh b/manage-i18n.sh new file mode 100755 index 0000000..94f135f --- /dev/null +++ b/manage-i18n.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +USAGE="$0 [init |extract|update |compile ]" + +if [[ "$1" == '-h' || "$1" == '--help' ]]; then + echo "$USAGE" + exit 0 +fi + +ACTION="$1" +LOCALE="$2" + +function require_locale { + if [[ -z "$LOCALE" ]]; then + echo "$USAGE" + exit 1 + fi +} + +if [[ ! "init extract update compile" =~ $ACTION ]]; then + echo "$USAGE" + exit 1 +fi + +for plugin in $(find . -name setup.py -exec sh -c 'basename $(dirname $0)' {} \;); do + pushd "${plugin}" >/dev/null + if [[ "$ACTION" == "init" ]]; then + require_locale + pybabel init -l "$LOCALE" -i "./indico_${plugin}/translations/messages.pot" -d "./indico_${plugin}/translations/" + elif [[ "$ACTION" == "extract" ]]; then + TRANSLATIONS_DIR="./indico_${plugin}/translations" + pybabel extract -o "${TRANSLATIONS_DIR}/messages.pot" "indico_${plugin}" -F ../babel.cfg + pybabel extract -o "${TRANSLATIONS_DIR}/messages-js.pot" "indico_${plugin}" -k 'gettext' -k 'ngettext' -k '$T' -F ../babel-js.cfg + elif [[ "$ACTION" == "update" ]]; then + require_locale + pybabel update -i "./indico_${plugin}/translations/messages.pot" -l "$LOCALE" -d "./indico_${plugin}/translations" + fi + popd >/dev/null +done diff --git a/run-tests.sh b/run-tests.sh old mode 100644 new mode 100755