Tools used by OpenStack Documentation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.9KB

  1. #!/bin/bash -xe
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. # Build English and translated version of project documentation
  15. DOCNAME=doc
  16. DIRECTORY=doc
  17. # clean build dir
  18. rm -rf ${DIRECTORY}/build/
  19. # create pot files
  20. sphinx-build -a -b gettext \
  21. -d ${DIRECTORY}/build/doctrees.gettext \
  22. ${DIRECTORY}/source ${DIRECTORY}/source/locale/
  23. # check all language translation resouce
  24. for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
  25. # skip if it is not a valid language translation resource.
  26. if [ ! -d ${locale}/LC_MESSAGES/ ]; then
  27. continue
  28. fi
  29. language=$(basename $locale)
  30. echo "===== Building $language translation ====="
  31. # prepare all translation resources
  32. for pot in ${DIRECTORY}/source/locale/*.pot ; do
  33. # get filename
  34. potname=$(basename $pot)
  35. resname=${potname%.pot}
  36. # skip if it is not a valid language translation resource.
  37. if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}-${resname}.po ]; then
  38. continue
  39. fi
  40. # merge all translation resources
  41. msgmerge -q -o \
  42. ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \
  43. ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}-${resname}.po \
  44. ${DIRECTORY}/source/locale/${potname}
  45. # compile all translation resources
  46. msgfmt -o \
  47. ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \
  48. ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po
  49. done
  50. # build lamguage version
  51. sphinx-build -a -b html -D language=${language} \
  52. -d ${DIRECTORY}/build/doctrees.languages/${language} \
  53. ${DIRECTORY}/source ${DIRECTORY}/build/html/${language}
  54. # remove newly created files
  55. git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po
  56. git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo
  57. git clean -f -x -q ${DIRECTORY}/source/locale/.doctrees
  58. # revert changes to po file
  59. git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
  60. git checkout -q -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
  61. done
  62. # remove generated pot files
  63. git clean -f -q ${DIRECTORY}/source/locale/*.pot
  64. # build english version
  65. sphinx-build -a -b html \
  66. -d ${DIRECTORY}/build/doctrees \
  67. ${DIRECTORY}/source ${DIRECTORY}/build/html/