Browse Source

add doc-tools-build-lang for build project docs with translations

this script should called by 'tox -edocs' in project documentation
if translations are available and need to build additionaly.

Change-Id: I016494185ba168ba72a8ad67eb0afe4a2875f5c5
changes/68/604568/1
Frank Kloeker 9 months ago
parent
commit
49cfcaf379
2 changed files with 78 additions and 0 deletions
  1. 77
    0
      bin/doc-tools-build-lang
  2. 1
    0
      setup.cfg

+ 77
- 0
bin/doc-tools-build-lang View File

@@ -0,0 +1,77 @@
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
+
15
+# Build English and translated version of project documentation
16
+
17
+DOCNAME=doc
18
+DIRECTORY=doc
19
+
20
+# clean build dir
21
+rm -rf  ${DIRECTORY}/build/
22
+
23
+# create pot files
24
+sphinx-build -a -b gettext \
25
+    -d ${DIRECTORY}/build/doctrees.gettext \
26
+    ${DIRECTORY}/source ${DIRECTORY}/source/locale/
27
+
28
+# check all language translation resouce
29
+for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
30
+    # skip if it is not a valid language translation resource.
31
+    if [ ! -d ${locale}/LC_MESSAGES/ ]; then
32
+        continue
33
+    fi
34
+    language=$(basename $locale)
35
+
36
+    echo "===== Building $language translation ====="
37
+
38
+    # prepare all translation resources
39
+    for pot in ${DIRECTORY}/source/locale/*.pot ; do
40
+        # get filename
41
+        potname=$(basename $pot)
42
+        resname=${potname%.pot}
43
+        # skip if it is not a valid language translation resource.
44
+        if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}-${resname}.po ]; then
45
+            continue
46
+        fi
47
+        # merge all translation resources
48
+        msgmerge -q -o \
49
+            ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \
50
+            ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}-${resname}.po \
51
+            ${DIRECTORY}/source/locale/${potname}
52
+        # compile all translation resources
53
+        msgfmt -o \
54
+            ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \
55
+            ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po
56
+    done
57
+
58
+    # build lamguage version
59
+    sphinx-build -a -b html -D language=${language} \
60
+            -d ${DIRECTORY}/build/doctrees.languages/${language} \
61
+            ${DIRECTORY}/source ${DIRECTORY}/build/html/${language}
62
+
63
+    # remove newly created files
64
+    git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po
65
+    git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo
66
+    git clean -f -x -q ${DIRECTORY}/source/locale/.doctrees
67
+    # revert changes to po file
68
+    git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
69
+    git checkout -q -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
70
+done
71
+# remove generated pot files
72
+git clean -f -q ${DIRECTORY}/source/locale/*.pot
73
+
74
+# build english version
75
+sphinx-build -a -b html \
76
+    -d ${DIRECTORY}/build/doctrees \
77
+    ${DIRECTORY}/source ${DIRECTORY}/build/html/

+ 1
- 0
setup.cfg View File

@@ -27,6 +27,7 @@ data_files =
27 27
 scripts =
28 28
     bin/doc-tools-check-languages
29 29
     bin/doc-tools-build-rst
30
+    bin/doc-tools-build-lang
30 31
 
31 32
 [global]
32 33
 setup-hooks =

Loading…
Cancel
Save