Extract translations for log messages
Create for each log level its own translation file and update it like the user visible translation file. Note that the debug log level does not get translated and thus is excluded. Take care that we handle empty pot files (transifex errors out on them) and no initial existing pot files. implements bp log-messages-translation-domain-rollout Change-Id: Ib2f6f2450526655c41c27f411fb2868076049068
This commit is contained in:
parent
bce62402bc
commit
d8f9604f9c
modules/openstack_project/files/slave_scripts
@ -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/<lang>/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
|
||||
}
|
||||
|
@ -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/*
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user