From fa662ca0919c2b12a7563db5aa688aa942a159e4 Mon Sep 17 00:00:00 2001 From: "Ian Y. Choi" Date: Sun, 28 Oct 2018 01:32:23 +0900 Subject: [PATCH] [tools] build-docs.sh: matches po files in Zanata Unlike guides in doc/source directory such as admin, contributor, and user, current build-docs.sh [1] cannot match pot files from rst files on doc/source folder such as index.pot generated from "sphinx-build -b gettext" with doc.po which actually has translated resources on the folder. This commit patches build-docs.sh to make: - if there is a corresponding doc-{resname}.po from {resname}.pot, then matching between those files is correct - if there is not a corresponding doc-{resname}.po, then matching with doc.pot is correct. - enhance a logic to revert po files since there are multiple po files to be reverted. Change-Id: I8d1899e9ff6697b9793105dca45b2753a3546266 --- tools/build-docs.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tools/build-docs.sh b/tools/build-docs.sh index d84fac0ffd..d276f00d5f 100755 --- a/tools/build-docs.sh +++ b/tools/build-docs.sh @@ -40,22 +40,29 @@ for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; 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} + # "{resname}.pot" needs to be merged with "doc-{resname}.po" if exists + if [ -e ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}-${resname}.po ]; then + msgmerge -q -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}-${resname}.po \ + ${DIRECTORY}/source/locale/${potname} + elif [ -e ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po ]; then + msgmerge -q -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \ + ${DIRECTORY}/source/locale/${potname} + else + msgcat ${DIRECTORY}/source/locale/${potname} > \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po + fi # 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 + # build language version sphinx-build -a -b html -D language=${language} \ -d ${DIRECTORY}/build/doctrees.languages/${language} \ ${DIRECTORY}/source ${DIRECTORY}/build/html/${language} @@ -65,8 +72,10 @@ for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do 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 + git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/ + for po in `git ls-files ${DIRECTORY}/source/locale/${language}/LC_MESSAGES` ; do + git checkout -q -- $po + done done # remove generated pot files git clean -f -q ${DIRECTORY}/source/locale/*.pot