Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commitb2d73aa

Browse files
committed
Merge remote-tracking branch 'upstream/3.6' into 3.6
2 parents0fb7ad4 +f2a1078 commitb2d73aa

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.mo
22
__pycache__
3+
.DS_Store

‎Makefile

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

‎scripts/fix_diffs.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
importsubprocess
2+
importre
3+
4+
STRING=r'"((?:[^\"]|\\|\")*)"'
5+
MSGID=r'^msgid '+STRING
6+
MSGSTR=r'^msgstr '+STRING
7+
8+
HEADERS= [
9+
'Project-Id-Version',
10+
'Report-Msgid-Bugs-To',
11+
'POT-Creation-Date',
12+
'PO-Revision-Date',
13+
'Last-Translator',
14+
'Language-Team',
15+
'Language',
16+
'MIME-Version',
17+
'Content-Type',
18+
'Content-Transfer-Encoding',
19+
'Plural-Forms',
20+
'X-Generator',
21+
]
22+
23+
defextract(lines,startline,first_line_regex=MSGID):
24+
first_line_match=re.match(first_line_regex,lines[startline])
25+
current_string=""
26+
iffirst_line_match:
27+
current_string+=first_line_match.group(1)
28+
lineno=startline+1
29+
whilelineno<len(lines):
30+
msg_match=re.match(STRING,lines[lineno])
31+
ifmsg_matchisNone:
32+
returncurrent_string,lines[startline:lineno],lineno
33+
else:
34+
current_string+=msg_match.group(1)
35+
lineno+=1
36+
else:
37+
returncurrent_string,lines[startline:lineno],lineno
38+
returnNone,None,startline
39+
40+
defget_msgs(lines):
41+
msgids= []
42+
msgstrs= []
43+
lineno=0
44+
whilelineno<len(lines):
45+
string,raw_lines,lineno=extract(lines,lineno,MSGID)
46+
ifstringisnotNone:
47+
msgids.append((string,raw_lines))
48+
continue
49+
string,raw_lines,lineno=extract(lines,lineno,MSGSTR)
50+
ifstringisnotNone:
51+
msgstrs.append((string,raw_lines))
52+
continue
53+
lineno+=1
54+
returnmsgids,msgstrs
55+
56+
defmain(fp):
57+
p=subprocess.Popen(['git','show','HEAD:'+fp],stdout=subprocess.PIPE)
58+
out,err=p.communicate()
59+
head_po=out.decode().splitlines()
60+
msgids,msgstrs=get_msgs(head_po)
61+
msgids=iter(msgids)
62+
msgstrs=iter(msgstrs)
63+
withopen(fp)asf:
64+
lines=f.read().splitlines()
65+
output_lines= []
66+
lineno=0
67+
whilelineno<len(lines):
68+
forfirst_line_regex,original_msgsin [(MSGID,msgids), (MSGSTR,msgstrs)]:
69+
string,raw_lines,lineno=extract(lines,lineno,first_line_regex)
70+
ifstringisnotNone:
71+
original_msg,original_lines=next(original_msgs)
72+
iforiginal_msgsismsgstrs:
73+
lines_in_msg=string.split('\\n')[:-1]
74+
forlineinlines_in_msg:
75+
ifnotany(line.startswith(h+':')forhinHEADERS):
76+
break
77+
else:
78+
delraw_lines[1:]
79+
forheader_lineinlines_in_msg:
80+
ifheader_line.startswith('Language: '):
81+
raw_lines.append('"Language: zh-Hant\\n"')
82+
else:
83+
raw_lines.append('"{}\\n"'.format(header_line))
84+
ifstring==original_msg:
85+
output_lines.extend(original_lines)
86+
else:
87+
output_lines.extend(raw_lines)
88+
break
89+
else:
90+
output_lines.append(lines[lineno])
91+
lineno+=1
92+
returnoutput_lines
93+
94+
95+
if__name__=='__main__':
96+
importsys
97+
iflen(sys.argv)<2:
98+
print('Usage: python fix_diffs.py <po_file_path>')
99+
100+
fp=sys.argv[1]
101+
output_lines=main(fp)
102+
103+
withopen(fp,'w')asf:
104+
f.writelines([s+'\n'forsinoutput_lines])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp