Switch translated release notes conditionals
This takes the logic of translated release notes conditional code into Ansible logic for clarity. Change-Id: I811ffa1aa9fdaf1e8acafa4959874df32a8558ab
This commit is contained in:
parent
74df19df6b
commit
622155cda7
@ -1,5 +1,10 @@
|
||||
# TODO(mordred) Put the translations logic into a sphinx plugin?
|
||||
- name: Build releasenotes contents
|
||||
- name: Check if translations exist for release notes
|
||||
stat:
|
||||
path: "{{ zuul_work_dir }}/releasenotes/source/locale"
|
||||
register: translations
|
||||
|
||||
- name: Prepare release note translations
|
||||
shell:
|
||||
chdir: '{{ zuul_work_dir }}'
|
||||
executable: /bin/bash
|
||||
@ -27,88 +32,87 @@
|
||||
["zh_CN"]="Chinese (China)"
|
||||
)
|
||||
|
||||
if [ -e ${DIRECTORY}/source/locale/ ]; then
|
||||
# Check that locale_dirs is really set, otherwise translations
|
||||
# will not work.
|
||||
if ! grep -q -E '^locale_dirs *=' $DIRECTORY/source/conf.py; then
|
||||
echo "Translations exist and locale_dirs missing in source/conf.py"
|
||||
exit 1
|
||||
# Check that locale_dirs is really set, otherwise translations
|
||||
# will not work.
|
||||
if ! grep -q -E '^locale_dirs *=' $DIRECTORY/source/conf.py; then
|
||||
echo "Translations exist and locale_dirs missing in source/conf.py"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REFERENCES=`mktemp`
|
||||
trap "rm -f -- '$REFERENCES'" EXIT
|
||||
|
||||
# Extract translations
|
||||
tox -e venv -- sphinx-build -b gettext \
|
||||
-d ${DIRECTORY}/build/doctrees.gettext \
|
||||
${DIRECTORY}/source/ \
|
||||
${DIRECTORY}/source/locale/
|
||||
|
||||
# Add links for translations to index file
|
||||
cat <<EOF >> ${REFERENCES}
|
||||
|
||||
Translated Release Notes
|
||||
========================
|
||||
|
||||
EOF
|
||||
|
||||
# Check all language translation resources
|
||||
for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
|
||||
# Skip if it is not a valid language translation resource.
|
||||
if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then
|
||||
continue
|
||||
fi
|
||||
language=$(basename $locale)
|
||||
|
||||
REFERENCES=`mktemp`
|
||||
trap "rm -f -- '$REFERENCES'" EXIT
|
||||
echo "Building $language translation"
|
||||
|
||||
# Extract translations
|
||||
tox -e venv -- sphinx-build -b gettext \
|
||||
-d ${DIRECTORY}/build/doctrees.gettext \
|
||||
${DIRECTORY}/source/ \
|
||||
${DIRECTORY}/source/locale/
|
||||
# Prepare all translation resources
|
||||
for pot in ${DIRECTORY}/source/locale/*.pot ; do
|
||||
# Get filename
|
||||
resname=$(basename ${pot} .pot)
|
||||
|
||||
# Add links for translations to index file
|
||||
cat <<EOF >> ${REFERENCES}
|
||||
|
||||
Translated Release Notes
|
||||
========================
|
||||
|
||||
EOF
|
||||
|
||||
# Check all language translation resources
|
||||
for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
|
||||
# Skip if it is not a valid language translation resource.
|
||||
if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then
|
||||
continue
|
||||
fi
|
||||
language=$(basename $locale)
|
||||
|
||||
echo "Building $language translation"
|
||||
|
||||
# Prepare all translation resources
|
||||
for pot in ${DIRECTORY}/source/locale/*.pot ; do
|
||||
# Get filename
|
||||
resname=$(basename ${pot} .pot)
|
||||
|
||||
# Merge all translation resources. Note this is done the same
|
||||
# way as done in common_translation_update.sh where we merge
|
||||
# all strings together in a single file.
|
||||
msgmerge --silent -o \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \
|
||||
${pot}
|
||||
# Compile all translation resources
|
||||
msgfmt -o \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po
|
||||
done
|
||||
|
||||
# Build translated document
|
||||
tox -e venv -- sphinx-build -b html -D language=${language} \
|
||||
-d "${DIRECTORY}/build/doctrees.${language}" \
|
||||
${DIRECTORY}/source/ ${DIRECTORY}/build/html/${language}
|
||||
|
||||
# Reference translated document from index file
|
||||
if [ ${LANG_NAME["${language}"]+_} ] ; then
|
||||
name=${LANG_NAME["${language}"]}
|
||||
name+=" (${language})"
|
||||
echo "* \`$name <${language}/index.html>\`__" >> ${REFERENCES}
|
||||
else
|
||||
echo "* \`${language} <${language}/index.html>\`__" >> ${REFERENCES}
|
||||
fi
|
||||
|
||||
# Remove newly created files
|
||||
git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po
|
||||
git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo
|
||||
# revert changes to po file
|
||||
git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
|
||||
git checkout -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
|
||||
# Merge all translation resources. Note this is done the same
|
||||
# way as done in common_translation_update.sh where we merge
|
||||
# all strings together in a single file.
|
||||
msgmerge --silent -o \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \
|
||||
${pot}
|
||||
# Compile all translation resources
|
||||
msgfmt -o \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \
|
||||
${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po
|
||||
done
|
||||
|
||||
# Now append our references to the index file. We cannot do this
|
||||
# earlier since the sphinx commands will read this file.
|
||||
cat ${REFERENCES} >> ${DIRECTORY}/source/index.rst
|
||||
# Build translated document
|
||||
tox -e venv -- sphinx-build -b html -D language=${language} \
|
||||
-d "${DIRECTORY}/build/doctrees.${language}" \
|
||||
${DIRECTORY}/source/ ${DIRECTORY}/build/html/${language}
|
||||
|
||||
# Remove newly created pot files
|
||||
rm -f ${DIRECTORY}/source/locale/*.pot
|
||||
fi
|
||||
# Reference translated document from index file
|
||||
if [ ${LANG_NAME["${language}"]+_} ] ; then
|
||||
name=${LANG_NAME["${language}"]}
|
||||
name+=" (${language})"
|
||||
echo "* \`$name <${language}/index.html>\`__" >> ${REFERENCES}
|
||||
else
|
||||
echo "* \`${language} <${language}/index.html>\`__" >> ${REFERENCES}
|
||||
fi
|
||||
|
||||
# Remove newly created files
|
||||
git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po
|
||||
git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo
|
||||
# revert changes to po file
|
||||
git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
|
||||
git checkout -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
|
||||
done
|
||||
|
||||
# Now append our references to the index file. We cannot do this
|
||||
# earlier since the sphinx commands will read this file.
|
||||
cat ${REFERENCES} >> ${DIRECTORY}/source/index.rst
|
||||
|
||||
# Remove newly created pot files
|
||||
rm -f ${DIRECTORY}/source/locale/*.pot
|
||||
when: translations.stat.exists == True
|
||||
|
||||
- name: Build release notes
|
||||
include_role:
|
||||
|
Loading…
x
Reference in New Issue
Block a user