diff --git a/bindep.txt b/bindep.txt index 9d0711133e..30316f5dad 100644 --- a/bindep.txt +++ b/bindep.txt @@ -38,3 +38,5 @@ libsemanage-python [platform:redhat] # Required for compressing collected log files in CI gzip +# Required to build language docs +gettext diff --git a/doc/requirements.txt b/doc/requirements.txt index b3abbc3a7b..3d969c3b63 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -8,3 +8,4 @@ openstackdocstheme>=1.18.1 # Apache-2.0 reno>=2.5.0 # Apache-2.0 sphinxmark>=0.1.14 # Apache-2.0 doc8>=0.6.0 # Apache-2.0 +bashate>=0.5.1 # Apache-2.0 diff --git a/doc/source/conf.py b/doc/source/conf.py index 7aceb931c5..343935cd0d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -353,3 +353,4 @@ sphinxmark_image = 'text' sphinxmark_text = watermark sphinxmark_text_color = (128, 128, 128) sphinxmark_text_size = 70 +locale_dirs = ['locale/'] diff --git a/tools/build-docs.sh b/tools/build-docs.sh new file mode 100755 index 0000000000..d84fac0ffd --- /dev/null +++ b/tools/build-docs.sh @@ -0,0 +1,77 @@ +#!/bin/bash -xe +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Build English and translated version of project documentation + +DOCNAME=doc +DIRECTORY=doc + +# clean build dir +rm -rf ${DIRECTORY}/build/ + +# create pot files +sphinx-build -a -b gettext \ + -d ${DIRECTORY}/build/doctrees.gettext \ + ${DIRECTORY}/source ${DIRECTORY}/source/locale/ + +# check all language translation resouce +for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do + # skip if it is not a valid language translation resource. + if [ ! -d ${locale}/LC_MESSAGES/ ]; then + continue + fi + language=$(basename $locale) + + echo "===== Building $language translation =====" + + # prepare all translation resources + for pot in ${DIRECTORY}/source/locale/*.pot ; do + # get filename + potname=$(basename $pot) + resname=${potname%.pot} + # skip if it is not a valid language translation resource. + if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}-${resname}.po ]; then + continue + fi + # merge all translation resources + msgmerge -q -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}-${resname}.po \ + ${DIRECTORY}/source/locale/${potname} + # compile all translation resources + msgfmt -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po + done + + # build lamguage version + sphinx-build -a -b html -D language=${language} \ + -d ${DIRECTORY}/build/doctrees.languages/${language} \ + ${DIRECTORY}/source ${DIRECTORY}/build/html/${language} + + # 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 + git clean -f -x -q ${DIRECTORY}/source/locale/.doctrees + # revert changes to po file + git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po + git checkout -q -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po +done +# remove generated pot files +git clean -f -q ${DIRECTORY}/source/locale/*.pot + +# build english version +sphinx-build -a -b html \ + -d ${DIRECTORY}/build/doctrees \ + ${DIRECTORY}/source ${DIRECTORY}/build/html/ diff --git a/tox.ini b/tox.ini index dcb717e881..f75e7cbdce 100644 --- a/tox.ini +++ b/tox.ini @@ -42,9 +42,9 @@ setenv = basepython = python3 deps = -r{toxinidir}/doc/requirements.txt commands= - bash -c "rm -rf doc/build" doc8 doc - sphinx-build -b html doc/source doc/build/html + bashate tools/build-docs.sh + {toxinidir}/tools/build-docs.sh