|
| 1 | +# Makefile for Chinese (Taiwan) Python Documentation |
| 2 | +# |
| 3 | +# Here is what you can do: |
| 4 | +# |
| 5 | +# - make # Automatically build an html local version |
| 6 | +# - make todo # To list remaining tasks |
| 7 | +# - make merge # To merge pot from upstream |
| 8 | +# - make fuzzy # To find fuzzy strings |
| 9 | +# - make progress # To compute current progression |
| 10 | +# - make upgrade_venv # To upgrade the venv that compiles the doc |
| 11 | +# |
| 12 | +# Modes are: autobuild-stable, autobuild-dev, and autobuild-html, |
| 13 | +# documented in gen/src/3.6/Doc/Makefile as we're only delegating the |
| 14 | +# real work to the Python Doc Makefile. |
| 15 | +# |
| 16 | +# Credits: Python Documentation French Translation Team (https://github.com/python/python-docs-fr) |
| 17 | + |
| 18 | +CPYTHON_CLONE := ../cpython/ |
| 19 | +SPHINX_CONF :=$(CPYTHON_CLONE)/Doc/conf.py |
| 20 | +LANGUAGE := zh_TW |
| 21 | +VENV := ~/.venvs/python-docs-i18n/ |
| 22 | +PYTHON :=$(shell which python3) |
| 23 | +MODE := autobuild-dev-html |
| 24 | +BRANCH =$(shell git describe --contains --all HEAD) |
| 25 | +JOBS = 1 |
| 26 | + |
| 27 | + |
| 28 | +.PHONY: all |
| 29 | +all:$(VENV)/bin/sphinx-build$(VENV)/bin/blurb$(SPHINX_CONF) |
| 30 | +mkdir -p$(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/ |
| 31 | +ln -nfs$(shell pwd)$(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/LC_MESSAGES |
| 32 | +.$(VENV)/bin/activate;$(MAKE) -C$(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D locale_dirs=locales -D language=$(LANGUAGE) -D gettext_compact=0'$(MODE) |
| 33 | + |
| 34 | + |
| 35 | +$(SPHINX_CONF): |
| 36 | +git clone --depth 1 --no-single-branch https://github.com/python/cpython.git$(CPYTHON_CLONE) |
| 37 | +cd$(CPYTHON_CLONE)&& git checkout$(BRANCH) |
| 38 | + |
| 39 | + |
| 40 | +$(VENV)/bin/activate: |
| 41 | +mkdir -p$(VENV) |
| 42 | +$(PYTHON) -m venv$(VENV) |
| 43 | + |
| 44 | + |
| 45 | +$(VENV)/bin/sphinx-build:$(VENV)/bin/activate |
| 46 | +.$(VENV)/bin/activate; python3 -m pip install sphinx python-docs-theme |
| 47 | + |
| 48 | + |
| 49 | +$(VENV)/bin/blurb:$(VENV)/bin/activate |
| 50 | +.$(VENV)/bin/activate; python3 -m pip install blurb |
| 51 | + |
| 52 | + |
| 53 | +.PHONY: upgrade_venv |
| 54 | +upgrade_venv:$(VENV)/bin/activate |
| 55 | +.$(VENV)/bin/activate; python3 -m pip install --upgrade sphinx python-docs-theme blurb |
| 56 | + |
| 57 | + |
| 58 | +.PHONY: progress |
| 59 | +progress: |
| 60 | +@python3 -c'import sys; print("{:.1%}".format(int(sys.argv[1]) / int(sys.argv[2])))'\ |
| 61 | +$(shell msgcat*.po*/*.po | msgattrib --translated | grep -c '^msgid')\ |
| 62 | +$(shell msgcat*.po*/*.po | grep -c '^msgid') |
| 63 | + |
| 64 | + |
| 65 | +.PHONY: todo |
| 66 | +todo: |
| 67 | +forfilein*.po*/*.po;doecho$$(msgattrib --untranslated$$file| grep ^msgid| sed 1d| wc -l )$$file;done| grep -v ^0| sort -gr |
| 68 | + |
| 69 | + |
| 70 | +.PHONY: merge |
| 71 | +merge: upgrade_venv |
| 72 | +ifneq "$(shell cd$(CPYTHON_CLONE) 2>/dev/null && git describe --contains --all HEAD)" "$(BRANCH)" |
| 73 | +$(error "You're merging from a different branch") |
| 74 | +endif |
| 75 | +(cd $(CPYTHON_CLONE)/Doc; rm -f build/NEWS) |
| 76 | +(cd $(CPYTHON_CLONE); $(VENV)/bin/sphinx-build -Q -b gettext -D gettext_compact=0 Doc pot/) |
| 77 | +find $(CPYTHON_CLONE)/pot/ -name '*.pot' |\ |
| 78 | + while read -r POT;\ |
| 79 | + do\ |
| 80 | + PO="./$$(echo "$$POT" | sed "s#$(CPYTHON_CLONE)/pot/##; s#\.pot\$$#.po#")";\ |
| 81 | + mkdir -p "$$(dirname "$$PO")";\ |
| 82 | + if [ -f "$$PO" ];\ |
| 83 | + then\ |
| 84 | + case "$$POT" in\ |
| 85 | + *whatsnew*) msgmerge --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\ |
| 86 | + *) msgmerge --backup=off --force-po -U "$$PO" "$$POT" ;;\ |
| 87 | + esac\ |
| 88 | + else\ |
| 89 | + msgcat -o "$$PO" "$$POT";\ |
| 90 | + fi\ |
| 91 | + done |
| 92 | + |
| 93 | + |
| 94 | +.PHONY: fuzzy |
| 95 | +fuzzy: |
| 96 | +forfilein*.po*/*.po;doecho$$(msgattrib --only-fuzzy --no-obsolete"$$file"| grep -c'#, fuzzy')$$file;done| grep -v ^0| sort -gr |
| 97 | + |
| 98 | + |
| 99 | +.PHONY: clean |
| 100 | +clean: |
| 101 | +rm*.mo*/*.mo |
| 102 | + |
| 103 | +.PHONY: clean-diff |
| 104 | +clean-diff:$(VENV)/bin/activate |
| 105 | +forfilein$$(git diff --name-only| grep'.po$$');do python3 scripts/fix_diffs.py$$file;done |