summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Kloeker <f.kloeker@telekom.de>2018-12-06 22:31:49 +0100
committerFrank Kloeker <f.kloeker@telekom.de>2018-12-07 07:50:58 +0100
commitf91deab8fefdda38d4414f8cf602840655cfb0e0 (patch)
tree9b314030cdf9d1ec18be37861362c9b2e257b107
parent9de6fb3d0e642d07abfc5ddce82337138425529c (diff)
Switch to translated docs build by openstackdocstheme
Notes
Notes (review): Code-Review+1: Andreas Jaeger <jaegerandi@gmail.com> Code-Review+2: Ian Y. Choi <ianyrchoi@gmail.com> Code-Review+2: Akihiro Motoki <amotoki@gmail.com> Workflow+1: Akihiro Motoki <amotoki@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 17 Dec 2018 03:16:12 +0000 Reviewed-on: https://review.openstack.org/623329 Project: openstack/i18n Branch: refs/heads/master
-rw-r--r--lower-constraints.txt2
-rw-r--r--requirements.txt8
-rw-r--r--test-requirements.txt8
-rwxr-xr-xtools/build-docs.sh178
-rw-r--r--tools/get-lang-display-name.py24
-rw-r--r--tox.ini6
6 files changed, 11 insertions, 215 deletions
diff --git a/lower-constraints.txt b/lower-constraints.txt
index b6fb3e7..2cecedf 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -20,7 +20,7 @@ monotonic==1.4
20msgpack==0.5.6 20msgpack==0.5.6
21netaddr==0.7.19 21netaddr==0.7.19
22netifaces==0.10.6 22netifaces==0.10.6
23openstackdocstheme==1.20.0 23openstackdocstheme==1.28
24oslo.config==5.2.0 24oslo.config==5.2.0
25oslo.context==2.20.0 25oslo.context==2.20.0
26oslo.i18n==3.20.0 26oslo.i18n==3.20.0
diff --git a/requirements.txt b/requirements.txt
index 393aa97..00454af 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,8 +2,8 @@
2# of appearance. Changing the order has an impact on the overall integration 2# of appearance. Changing the order has an impact on the overall integration
3# process, which may cause wedges in the gate later. 3# process, which may cause wedges in the gate later.
4beautifulsoup4>=4.6.0 # MIT 4beautifulsoup4>=4.6.0 # MIT
5lxml!=3.7.0,>=3.4.1 # BSD 5lxml!=3.7.0,>=4.1.1 # BSD
6oslo.log>=3.36.0 # Apache-2.0 6oslo.log>=3.37.0 # Apache-2.0
7requests>=2.14.2 # Apache-2.0 7requests>=2.18.4 # Apache-2.0
8six>=1.10.0 # MIT 8six>=1.11.0 # MIT
9PyYAML>=3.12 # MIT 9PyYAML>=3.12 # MIT
diff --git a/test-requirements.txt b/test-requirements.txt
index cb5e116..8e3d5fc 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -4,7 +4,7 @@
4 4
5hacking<0.11,>=0.10.2 # Apache-2.0 5hacking<0.11,>=0.10.2 # Apache-2.0
6 6
7Babel!=2.4.0,>=2.3.4 # BSD 7Babel!=2.4.0,>=2.5.3 # BSD
8sphinx!=1.6.6,!=1.6.7,>=1.6.2 # BSD 8sphinx!=1.6.6,!=1.6.7,>=1.6.5 # BSD
9openstackdocstheme>=1.18.1 # Apache-2.0 9openstackdocstheme>=1.28 # Apache-2.0
10doc8>=0.6.0 # Apache-2.0 10doc8>=0.8.0 # Apache-2.0
diff --git a/tools/build-docs.sh b/tools/build-docs.sh
deleted file mode 100755
index c43d3d7..0000000
--- a/tools/build-docs.sh
+++ /dev/null
@@ -1,178 +0,0 @@
1#!/bin/bash
2
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16# Build English and translated version of the I18n guide.
17
18set -e
19set -x
20
21DOCNAME=doc
22DIRECTORY=doc
23
24# build i18n contributor guide page
25sphinx-build -a -W -b html \
26 -d ${DIRECTORY}/build/doctrees \
27 ${DIRECTORY}/source ${DIRECTORY}/build/html/
28
29if [ "${NO_LANG_BUILD:-0}" = "1" ]; then
30 exit 0
31fi
32
33# This function sets the following global variables
34# - LANG_INDEX : filename which contains the language index
35# - HAS_LANG : 1 (there are languages other than English), 0 (English only)
36function prepare_language_index {
37 # Global variables
38 HAS_LANG=0
39 LANG_INDEX=`mktemp`
40 trap "rm -f -- $LANG_INDEX" EXIT
41
42 cat <<EOF >> $LANG_INDEX
43[
44\`English <__BASE__/__INDEX__>\`__
45EOF
46
47 # Generate language index file
48 for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
49 # skip if it is not a valid language translation resource.
50 if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then
51 continue
52 fi
53 language=$(basename $locale)
54
55 # Reference translated document from index file
56 echo -n "| " >> $LANG_INDEX
57 HAS_LANG=1
58 get_lang_name_prog=$(dirname $0)/get-lang-display-name.py
59 name=`python3 $get_lang_name_prog $language`
60 echo "\`$name <__BASE__/${language}/__INDEX__>\`__" >> $LANG_INDEX
61 done
62
63 cat <<EOF >> $LANG_INDEX
64]
65
66EOF
67}
68
69function _add_language_index {
70 local target_file=$1
71 local basepath=$2
72
73 local basename
74 basename=$(echo $target_file | sed -e "s|$DIRECTORY/source/||" -e "s|\.rst$||")
75 path_to_top_level=$(dirname $basename | sed -e 's|[^./]\+|..|g')
76
77 local _basepath
78 if [ "$basepath" = "." -a "$path_to_top_level" = "." ]; then
79 _basepath="."
80 elif [ "$basepath" = "." ]; then
81 _basepath=$path_to_top_level
82 elif [ "$path_to_top_level" = "." ]; then
83 _basepath=$basepath
84 else
85 _basepath="$basepath/$path_to_top_level"
86 fi
87
88 cp -p $target_file $target_file.backup
89 sed -e "s|__BASE__|$_basepath|" -e "s|__INDEX__|$basename.html|" $LANG_INDEX > $target_file
90 cat $target_file.backup >> $target_file
91}
92
93function add_language_index_to_localized {
94 for f in `find $DIRECTORY/source -name '*.rst'`; do
95 _add_language_index $f ..
96 done
97}
98
99function add_language_index_to_original {
100 for f in `find $DIRECTORY/source -name '*.rst'`; do
101 cp -p $f.backup $f
102 _add_language_index $REFERENCES $f .
103 done
104}
105
106function recover_rst_files {
107 for f in `find $DIRECTORY/source -name '*.rst'`; do
108 mv $f.backup $f
109 done
110}
111
112sphinx-build -a -W -b gettext \
113 -d ${DIRECTORY}/build/doctrees.gettext \
114 ${DIRECTORY}/source ${DIRECTORY}/source/locale/
115
116prepare_language_index
117if [ "$HAS_LANG" = "0" ]; then
118 exit 0
119fi
120# Now add our references to the beginning of the index file. We cannot do this
121# earlier since the sphinx commands will read this file.
122# Ensure to revert any changes to the index file.
123add_language_index_to_localized
124
125# check all language translation resource
126for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
127 # skip if it is not a valid language translation resource.
128 if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then
129 continue
130 fi
131 language=$(basename $locale)
132
133 echo "===== Building $language translation ====="
134
135 # prepare all translation resources
136 for pot in ${DIRECTORY}/source/locale/*.pot ; do
137 # get filename
138 potname=$(basename $pot)
139 resname=${potname%.pot}
140 echo $resname
141 # merge all translation resources
142 msgmerge --silent -o \
143 ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \
144 ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \
145 ${DIRECTORY}/source/locale/${potname}
146 # compile all translation resources
147 msgfmt -o \
148 ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \
149 ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po
150 done
151
152 # build translated guide
153 # build i18n contributor guide page
154 # TODO(amotoki): Enable -W option in translated version
155 sphinx-build -a -b html -D language=${language} \
156 -d ${DIRECTORY}/build/doctrees.languages/${language} \
157 ${DIRECTORY}/source ${DIRECTORY}/build/html/${language}
158
159 # remove newly created files
160 git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po
161 git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo
162 git clean -f -x -q ${DIRECTORY}/source/locale/.doctrees
163 # revert changes to po file
164 git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
165 git checkout -q -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
166done
167
168# remove newly created pot files
169rm -f ${DIRECTORY}/source/locale/*.pot
170
171add_language_index_to_original
172
173# build i18n contributor guide page
174sphinx-build -a -W -b html \
175 -d ${DIRECTORY}/build/doctrees \
176 ${DIRECTORY}/source ${DIRECTORY}/build/html/
177
178recover_rst_files
diff --git a/tools/get-lang-display-name.py b/tools/get-lang-display-name.py
deleted file mode 100644
index 80b7de4..0000000
--- a/tools/get-lang-display-name.py
+++ /dev/null
@@ -1,24 +0,0 @@
1# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10# implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import sys
15
16import babel
17
18
19lang_code = sys.argv[1]
20try:
21 l = babel.Locale.parse(lang_code)
22 print(l.get_display_name())
23except Exception:
24 print(lang_code)
diff --git a/tox.ini b/tox.ini
index 8748cbb..af4bba9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,7 +5,7 @@ skipsdist = True
5 5
6[testenv] 6[testenv]
7basepython=python3 7basepython=python3
8install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} 8#install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
9usedevelop = True 9usedevelop = True
10setenv = VIRTUAL_ENV={envdir} 10setenv = VIRTUAL_ENV={envdir}
11deps = -r{toxinidir}/requirements.txt 11deps = -r{toxinidir}/requirements.txt
@@ -27,12 +27,10 @@ commands = {posargs}
27passenv = 27passenv =
28 # Required by add-marker.sh 28 # Required by add-marker.sh
29 ZUUL* 29 ZUUL*
30 # Pass NO_LANG_BUILD=1 if you would like to build English version only
31 NO_LANG_BUILD
32commands = 30commands =
33 doc8 doc/source 31 doc8 doc/source
34 # Build translated guides 32 # Build translated guides
35 {toxinidir}/tools/build-docs.sh 33 docstheme-build-translated.sh
36 34
37[testenv:pep8] 35[testenv:pep8]
38commands = 36commands =