diff --git a/modules/openstack_project/files/slave_scripts/common_translation_update.sh b/modules/openstack_project/files/slave_scripts/common_translation_update.sh index 7509c7d8d6..f3befd53de 100644 --- a/modules/openstack_project/files/slave_scripts/common_translation_update.sh +++ b/modules/openstack_project/files/slave_scripts/common_translation_update.sh @@ -116,3 +116,52 @@ EOF fi } + +# Setup global variables LEVELS and LKEYWORDS +function setup_loglevel_vars () +{ + # Strings for various log levels + LEVELS="info warning error critical" + # Keywords for each log level: + declare -g -A LKEYWORD + LKEYWORD['info']='_LI' + LKEYWORD['warning']='_LW' + LKEYWORD['error']='_LE' + LKEYWORD['critical']='_LC' +} + +# Setup transifex configuration for log level message translation. +# Needs variables setup via setup_loglevel_vars. +function setup_loglevel_project () +{ + project=$1 + + for level in $LEVELS ; do + # Bootstrapping: Create file if it does not exist yet, + # otherwise "tx set" will fail. + if [ ! -e ${project}/locale/${project}-log-${level}.pot ] + then + touch ${project}/locale/${project}-log-${level}.pot + fi + tx set --auto-local -r ${project}.${project}-log-${level}-translations \ + "${project}/locale//LC_MESSAGES/${project}-log-${level}.po" \ + --source-lang en \ + --source-file ${project}/locale/${project}-log-${level}.pot -t PO \ + --execute + done +} + +# Run extract_messages for user visible messages and log messages. +# Needs variables setup via setup_loglevel_vars. +function extract_messages_log () +{ + project=$1 + + # Update the .pot files + python setup.py extract_messages + for level in $LEVELS ; do + python setup.py extract_messages --no-default-keywords \ + --keyword ${LKEYWORD[$level]} \ + --output-file ${project}/locale/${project}-log-${level}.pot + done +} diff --git a/modules/openstack_project/files/slave_scripts/propose_translation_update.sh b/modules/openstack_project/files/slave_scripts/propose_translation_update.sh index a739cea75c..e0b51374ef 100755 --- a/modules/openstack_project/files/slave_scripts/propose_translation_update.sh +++ b/modules/openstack_project/files/slave_scripts/propose_translation_update.sh @@ -23,18 +23,37 @@ setup_review "$ORG" "$PROJECT" setup_translation setup_project "$PROJECT" +setup_loglevel_vars +setup_loglevel_project "$PROJECT" + # Pull upstream translations of files that are at least 75 % # translated tx pull -a -f --minimum-perc=75 -# Update the .pot file -python setup.py extract_messages -PO_FILES=`find ${PROJECT}/locale -name '*.po'` +extract_messages_log "$PROJECT" + +PO_FILES=`find ${PROJECT}/locale -name "${PROJECT}.po"` if [ -n "$PO_FILES" ] then # Use updated .pot file to update translations python setup.py update_catalog --no-fuzzy-matching --ignore-obsolete=true fi +# We cannot run update_catlog for the log files, since there is no +# option to specify the keyword and thus an update_catalog run would +# add the messages with the default keywords. Therefore use msgmerge +# directly. +for level in $LEVELS ; do + PO_FILES=`find ${PROJECT}/locale -name "${PROJECT}-log-${level}.po"` + if [ -n "$PO_FILES" ] + then + for f in $PO_FILES ; do + echo "Updating $f" + msgmerge --update --no-fuzzy-matching $f \ + ${PROJECT}/locale/${PROJECT}-log-${level}.pot + done + fi +done + # Add all changed files to git git add $PROJECT/locale/* diff --git a/modules/openstack_project/files/slave_scripts/upstream_translation_update.sh b/modules/openstack_project/files/slave_scripts/upstream_translation_update.sh index 55f99b43aa..3b3c06ce27 100755 --- a/modules/openstack_project/files/slave_scripts/upstream_translation_update.sh +++ b/modules/openstack_project/files/slave_scripts/upstream_translation_update.sh @@ -25,8 +25,10 @@ setup_git setup_translation setup_project "$PROJECT" -# Update the .pot file -python setup.py extract_messages +setup_loglevel_vars +setup_loglevel_project "$PROJECT" + +extract_messages_log "$PROJECT" # Add all changed files to git git add $PROJECT/locale/* @@ -34,5 +36,14 @@ git add $PROJECT/locale/* if [ ! `git diff-index --quiet HEAD --` ] then # Push .pot changes to transifex - tx --debug --traceback push -s + tx --debug --traceback push -s -r ${PROJECT}.${PROJECT}-translations + for level in $LEVELS ; do + # Only push if there is actual content in the file. We check + # that the file contains at least one non-empty msgid string. + if grep -q 'msgid "[^"]' ${PROJECT}/locale/${PROJECT}-log-${level}.pot + then + tx --debug --traceback push -s \ + -r ${PROJECT}.${PROJECT}-log-${level}-translations + fi + done fi