Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit fa3ac0d

Browse files
chore: Add build tools for translations
Signed-off-by: Wolfgang Walther <[email protected]>
1 parent 43a92d4 commit fa3ac0d

File tree

7 files changed

+104
-16
lines changed

7 files changed

+104
-16
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Pipfile.lock
44
*.log
55
diagrams/db.pdf
66
misspellings
7+
*.mo

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ Once in the nix-shell you have the following commands available:
1818

1919
This documentation is structured according to tutorials-howtos-topics-references. For more details on the rationale of this structure,
2020
see https://www.divio.com/blog/documentation.
21+
22+
## Translating
23+
24+
To create `.po` files for translation into a new language pass the language code as the first argument to `postgrest-docs-build`.
25+
26+
Example to add German/de:
27+
28+
```
29+
postgrest-docs-build de
30+
```
31+
32+
The livereload server also supports a language/locale argument to show the translated docs during translation:
33+
34+
```
35+
postgrest-docs-serve de
36+
```
37+
38+
Spellcheck is currently only available for the default language.

Diff for: build.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function build() {
5+
sphinx-build --color -W -a -n docs -b "$@"
6+
}
7+
8+
if [ $# -eq 0 ]; then
9+
# clean previous build, otherwise some errors might be supressed
10+
rm -rf "_build/html/default"
11+
12+
# default to updating all existing locales
13+
build gettext _build/gettext
14+
sphinx-intl update -p _build/gettext
15+
16+
build html "_build/html/default"
17+
else
18+
# clean previous build, otherwise some errors might be supressed
19+
rm -rf "_build/html/$1"
20+
21+
# update and build specific locale, can be used to create new locale
22+
build gettext _build/gettext
23+
sphinx-intl update -p _build/gettext -l "$1"
24+
25+
build html "_build/html/$1" -D "language=$1"
26+
fi

Diff for: default.nix

+14-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ let
1717

1818
sphinxTabsPkg = ps: ps.callPackage ./extensions/sphinx-tabs.nix {};
1919
sphinxCopybuttonPkg = ps: ps.callPackage ./extensions/sphinx-copybutton.nix {};
20-
21-
python = pkgs.python3.withPackages (ps: [ ps.sphinx ps.sphinx_rtd_theme ps.livereload (sphinxTabsPkg ps) (sphinxCopybuttonPkg ps) ]);
20+
sphinxIntlPkg = ps: ps.callPackage ./extensions/sphinx-intl.nix {};
21+
22+
python = pkgs.python3.withPackages (ps: [
23+
ps.sphinx
24+
ps.sphinx_rtd_theme
25+
ps.livereload
26+
(sphinxTabsPkg ps)
27+
(sphinxCopybuttonPkg ps)
28+
(sphinxIntlPkg ps)
29+
]);
2230
in
2331
{
2432
inherit pkgs;
@@ -28,10 +36,10 @@ in
2836
''
2937
set -euo pipefail
3038
31-
# clean previous build, otherwise some errors might be supressed
32-
rm -rf _build
39+
# build.sh needs to find "sphinx-build"
40+
PATH=${python}/bin:$PATH
3341
34-
${python}/bin/sphinx-build --color -W -b html -a -n docs _build
42+
./build.sh "$@"
3543
'';
3644

3745
serve =
@@ -42,7 +50,7 @@ in
4250
# livereload_docs.py needs to find "sphinx-build"
4351
PATH=${python}/bin:$PATH
4452
45-
${python}/bin/python livereload_docs.py
53+
./livereload_docs.py "$@"
4654
'';
4755

4856
spellcheck =

Diff for: extensions/sphinx-intl.nix

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ buildPythonPackage
2+
, click
3+
, fetchPypi
4+
, lib
5+
, sphinx
6+
}:
7+
8+
buildPythonPackage rec {
9+
pname = "sphinx-intl";
10+
version = "2.0.1";
11+
12+
src = fetchPypi {
13+
inherit pname version;
14+
sha256 = "sha256:1d1q0sanjp4nkfvhsxi75zf3xjyyi8nzxvl3v7l0jy9ld70nwnmj";
15+
};
16+
17+
propagatedBuildInputs = [
18+
click
19+
sphinx
20+
];
21+
22+
doCheck = false;
23+
24+
meta = with lib; {
25+
description = "Sphinx utility that make it easy to translate and to apply translation.";
26+
homepage = "https://sphinx-intl.readthedocs.io";
27+
license = licenses.bsd2;
28+
};
29+
}

Diff for: livereload_docs.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#!/usr/bin/env python
2+
import sys
23
from livereload import Server, shell
34
from subprocess import call
4-
## Build docs at startup
5-
call(['sphinx-build', '-b', 'html', '-a', '-n', 'docs', '_build'])
5+
6+
if len(sys.argv) == 1:
7+
locale = 'default'
8+
build = './build.sh'
9+
else:
10+
locale = sys.argv[1]
11+
build = f'./build.sh {locale}'
12+
13+
call(build, shell=True)
14+
615
server = Server()
7-
server.watch('*.rst', shell('sphinx-build -b html -a -n docs _build'))
8-
server.watch('tutorials/*.rst', shell('sphinx-build -b html -a -n docs _build'))
9-
server.watch('how-tos/*.rst', shell('sphinx-build -b html -a -n docs _build'))
10-
server.watch('releases/*.rst', shell('sphinx-build -b html -a -n docs _build'))
11-
# For custom port and host
12-
# server.serve(root='_build/', host='192.168.1.2')
13-
server.serve(root='_build/')
16+
server.watch('docs/**/*.rst', shell(build))
17+
server.watch(f'locales/{locale}/LC_MESSAGES/*.po', shell(build))
18+
server.serve(root=f'_build/html/{locale}')

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
docutils<0.18
22
sphinx-tabs
3-
sphinx-copybutton
3+
sphinx-copybutton
4+
sphinx-intl

0 commit comments

Comments
 (0)