forked from taichi-dev/taichi-docs-zh-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
89 lines (66 loc) · 2.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Makefile for Chinese (Simplified) Taichi Documentation
#
# Here is what you can do:
#
# - make # Automatically build an html local version
# - make todo # To list remaining tasks
# - make merge # To merge pot from upstream
# - make fuzzy # To find fuzzy strings
# - make progress # To compute current progression
# - make upgrade_venv # To upgrade the venv that compiles the doc
#
# Credits: Taichi Documentation Chinese Translation Team (https://github.com/stephenark30/taichi-docs-zh-cn)
TAICHI_CLONE := ./taichi
LANGUAGE := zh_CN
LC_MESSAGES := ./locales/$(LANGUAGE)/LC_MESSAGES
VENV := ./.venvs/taichi-docs-zh-cn
PYTHON := $(shell which python3)
BRANCH = $(shell git symbolic-ref --short -q HEAD)
.PHONY: all
all: $(TAICHI_CLONE)/docs $(VENV)/bin/sphinx-build merge
$(TAICHI_CLONE)/docs:
git submodule init
git submodule update
cd $(TAICHI_CLONE) && git checkout $(BRANCH)
$(VENV)/bin/activate:
mkdir -p $(VENV)
$(PYTHON) -m venv $(VENV)
$(VENV)/bin/sphinx-build: $(VENV)/bin/activate
. $(VENV)/bin/activate; python3 -m pip install Sphinx sphinx_rtd_theme sphinx-intl
.PHONY: upgrade_venv
upgrade_venv: $(VENV)/bin/activate
. $(VENV)/bin/activate; python3 -m pip install --upgrade Sphinx sphinx_rtd_theme sphinx-intl
.PHONY: progress
progress:
@python3 -c 'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))' \
$(shell msgcat $(LC_MESSAGES)/*.po | msgattrib --translated | grep -c '^msgid') \
$(shell msgcat $(LC_MESSAGES)/*.po | grep -c '^msgid')
.PHONY: todo
todo:
for file in $(LC_MESSAGES)/*.po; do echo $$(msgattrib --untranslated $$file | grep ^msgid | sed 1d | wc -l ) $$file; done | grep -v ^0 | sort -gr
.PHONY: merge
merge: upgrade_venv
ifneq "$(shell cd $(TAICHI_CLONE) 2>/dev/null && git symbolic-ref --short -q HEAD)" "$(BRANCH)"
$(error "You're merging from a different branch, please cd $(TAICHI_CLONE) && git checkout $(BRANCH)")
endif
# files might be renamed in the origin doc, so we have to delete old files
rm -rf ./*.rst ./*.jpg ./*.png ./_static ./version ./conf.py
cd $(TAICHI_CLONE); git checkout -- ./; git pull;
cp $(TAICHI_CLONE)/docs/*.rst ./
cp $(TAICHI_CLONE)/docs/*.jpg ./
cp $(TAICHI_CLONE)/docs/*.png ./
cp -r $(TAICHI_CLONE)/docs/_static ./
cp $(TAICHI_CLONE)/docs/version ./
cp $(TAICHI_CLONE)/docs/conf.py ./
echo "gettext_additional_targets = ['literal-block']" >> conf.py
echo "locale_dirs = ['locales/']" >> conf.py
. $(VENV)/bin/activate; $(VENV)/bin/sphinx-build -M gettext . build; $(VENV)/bin/sphinx-intl update -p build/gettext -l $(LANGUAGE)
.PHONY: html
html:
. $(VENV)/bin/activate; sphinx-build -M html . build -D language='$(LANGUAGE)'
.PHONY: fuzzy
fuzzy:
for file in $(LC_MESSAGES)/*.po; do echo $$(msgattrib --only-fuzzy --no-obsolete "$$file" | grep -c '#, fuzzy') $$file; done | grep -v ^0 | sort -gr
ifdef QUIET
.SILENT:
endif