Skip to content

Commit e9f91fa

Browse files
committed
1 parent ae88038 commit e9f91fa

File tree

1 file changed

+58
-92
lines changed

1 file changed

+58
-92
lines changed

zh.diff

+58-92
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
From 89d9ddfb25ecd6b0f974ac65dc0ef01a6c42e29e Mon Sep 17 00:00:00 2001
1+
From 59e3c1e8105477b5b6c78ef0579a3f809ef89949 Mon Sep 17 00:00:00 2001
22
From: myfreeer <[email protected]>
3-
Date: Sun, 30 Dec 2018 17:35:34 +0800
3+
Date: Fri, 5 Apr 2019 07:50:59 +0800
44
Subject: [PATCH] source: use zh localized version
55

66
---
77
Makefile | 54 ++++++++++++------------
8-
commands/preprocess.py | 19 +++++----
9-
commands/preprocess_cssless.py | 5 ++-
10-
gadgets/standard_revisions-tests/base.py | 2 +-
8+
commands/preprocess.py | 21 +++++----
9+
commands/preprocess_cssless.py | 4 +-
10+
gadgets/standard_revisions_tests/base.py | 2 +-
1111
gadgets/sync_tests_mwiki.py | 2 +-
1212
index2ddg.py | 4 +-
1313
index_transform/browser.py | 2 +-
1414
preprocess.py | 8 ++--
15-
tests/test_preprocess.py | 19 ++++++---
15+
tests/test_preprocess.py | 2 +-
1616
tests/test_preprocess_cssless.py | 2 +-
17-
10 files changed, 64 insertions(+), 53 deletions(-)
17+
10 files changed, 52 insertions(+), 49 deletions(-)
1818

1919
diff --git a/Makefile b/Makefile
20-
index 2366fbc..423be32 100644
20+
index e54b72d..84d98a5 100644
2121
--- a/Makefile
2222
+++ b/Makefile
2323
@@ -100,18 +100,18 @@ install: all
@@ -94,14 +94,14 @@ index 2366fbc..423be32 100644
9494
-output/cppreference-doc-en-cpp.qch: output/qch-help-project-cpp.xml
9595
+output/cppreference-doc-zh-cpp.qch: output/qch-help-project-cpp.xml
9696
#qhelpgenerator only works if the project file is in the same directory as the documentation
97-
cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.xml"
97+
cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.qhp"
9898

9999
pushd "output/reference_cssless" > /dev/null; \
100-
- $(qhelpgenerator) "qch.xml" -o "../cppreference-doc-en-cpp.qch"; \
101-
+ $(qhelpgenerator) "qch.xml" -o "../cppreference-doc-zh-cpp.qch"; \
100+
- $(qhelpgenerator) "qch.qhp" -o "../cppreference-doc-en-cpp.qch"; \
101+
+ $(qhelpgenerator) "qch.qhp" -o "../cppreference-doc-zh-cpp.qch"; \
102102
popd > /dev/null
103103

104-
rm -f "output/reference_cssless/qch.xml"
104+
rm -f "output/reference_cssless/qch.qhp"
105105

106106
-output/qch-help-project-cpp.xml: output/cppreference-doc-en-cpp.devhelp2 output/reference_cssless
107107
+output/qch-help-project-cpp.xml: output/cppreference-doc-zh-cpp.devhelp2 output/reference_cssless
@@ -149,10 +149,10 @@ index 2366fbc..423be32 100644
149149
- ./export.py --url=http://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
150150
+ ./export.py --url=https://zh.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
151151
diff --git a/commands/preprocess.py b/commands/preprocess.py
152-
index 7a0cd5c..16dc1b2 100644
152+
index 2f8ff4c..43a527a 100644
153153
--- a/commands/preprocess.py
154154
+++ b/commands/preprocess.py
155-
@@ -41,15 +41,15 @@ def rearrange_archive(root):
155+
@@ -42,23 +42,23 @@ def rearrange_archive(root):
156156
# rearrange the archive. {root} here is output/reference
157157

158158
# before
@@ -172,16 +172,17 @@ index 7a0cd5c..16dc1b2 100644
172172
# ... (other languages)
173173

174174
data_path = os.path.join(root, 'common')
175-
@@ -57,7 +57,7 @@ def rearrange_archive(root):
175+
rmtree_if_exists(data_path)
176176
shutil.move(os.path.join(root, 'upload.cppreference.com/mwiki'), data_path)
177-
shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
177+
- shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
178+
+ shutil.rmtree(os.path.join(root, 'upload.cppreference.com'), ignore_errors=True)
178179

179180
- for lang in ["en"]:
180181
+ for lang in ["zh"]:
181182
path = os.path.join(root, lang + ".cppreference.com/")
182183
src_html_path = path + "w/"
183184
src_data_path = path + "mwiki/"
184-
@@ -78,7 +78,7 @@ def rearrange_archive(root):
185+
@@ -81,7 +81,7 @@ def rearrange_archive(root):
185186
shutil.copy(os.path.join(path, 'favicon.ico'), data_path)
186187

187188
# remove what's left
@@ -190,7 +191,7 @@ index 7a0cd5c..16dc1b2 100644
190191

191192
# remove the XML source file
192193
for fn in fnmatch.filter(os.listdir(root), 'cppreference-export*.xml'):
193-
@@ -309,7 +309,10 @@ def remove_fileinfo(html):
194+
@@ -341,7 +341,10 @@ def remove_fileinfo(html):
194195

195196
# make custom footer
196197
def add_footer(html, root, fn):
@@ -202,8 +203,8 @@ index 7a0cd5c..16dc1b2 100644
202203
for child in footer.getchildren():
203204
id = child.get('id')
204205
if id == 'cpp-navigation':
205-
@@ -340,7 +343,7 @@ def remove_unused_external(html):
206-
el.set('href', os.path.join(head, 'common', tail))
206+
@@ -377,7 +380,7 @@ def remove_unused_external(html):
207+
207208

208209
def preprocess_html_file(root, fn, rename_map):
209210
- parser = etree.HTMLParser()
@@ -212,14 +213,11 @@ index 7a0cd5c..16dc1b2 100644
212213
output = io.StringIO()
213214

214215
diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py
215-
index 2f75d5a..0aa10db 100644
216+
index 8bf9142..2df1774 100644
216217
--- a/commands/preprocess_cssless.py
217218
+++ b/commands/preprocess_cssless.py
218-
@@ -27,11 +27,12 @@ import io
219-
import logging
220-
import os
221-
import warnings
222-
+import codecs
219+
@@ -28,9 +28,9 @@ from lxml.etree import strip_elements
220+
223221

224222
def preprocess_html_merge_cssless(src_path, dst_path):
225223
- with open(src_path, 'r') as a_file:
@@ -230,11 +228,11 @@ index 2f75d5a..0aa10db 100644
230228
stripped = content.strip()
231229
root = etree.fromstring(stripped, parser)
232230

233-
diff --git a/gadgets/standard_revisions-tests/base.py b/gadgets/standard_revisions-tests/base.py
234-
index 848d431..91a0a99 100644
235-
--- a/gadgets/standard_revisions-tests/base.py
236-
+++ b/gadgets/standard_revisions-tests/base.py
237-
@@ -27,7 +27,7 @@ import unittest, time, re
231+
diff --git a/gadgets/standard_revisions_tests/base.py b/gadgets/standard_revisions_tests/base.py
232+
index b780e8d..67266e1 100644
233+
--- a/gadgets/standard_revisions_tests/base.py
234+
+++ b/gadgets/standard_revisions_tests/base.py
235+
@@ -24,7 +24,7 @@ from selenium.webdriver.support.ui import Select
238236

239237
class Driver:
240238
def __init__(self):
@@ -257,46 +255,46 @@ index 9aa3fc7..13294ec 100755
257255
pywikibot.config2.step = 100
258256
pywikibot.config2.put_throttle = 0
259257
diff --git a/index2ddg.py b/index2ddg.py
260-
index 9789e56..32a8707 100755
258+
index 0cfa557..36bcb45 100755
261259
--- a/index2ddg.py
262260
+++ b/index2ddg.py
263-
@@ -447,7 +447,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
264-
abstract = abstract.replace('\n','\\n')
261+
@@ -465,7 +465,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
262+
abstract = abstract.replace('\n', '\\n')
265263
line += abstract + '\t'
266264
# source url
267265
- line += 'http://en.cppreference.com/w/' + link + '\n'
268266
+ line += 'https://zh.cppreference.com/w/' + link + '\n'
269267
out.write(line)
270268

271269
build_redirects(redirects, item_ident, item_type)
272-
@@ -540,7 +540,7 @@ def main():
273-
#print(str(i) + '/' + str(len(proc_ins)) + ': ' + link)
274-
#i+=1
270+
@@ -580,7 +580,7 @@ def main():
271+
# i+=1
275272

276-
- root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser())
277-
+ root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser(encoding="utf-8"))
273+
root = e.parse(os.path.join(args.reference, fn),
274+
- parser=html.HTMLParser())
275+
+ parser=html.HTMLParser(encoding="utf-8"))
278276

279277
for ident in idents:
280278

281279
diff --git a/index_transform/browser.py b/index_transform/browser.py
282-
index d2e625c..11375f2 100644
280+
index fb8b976..e9657a4 100644
283281
--- a/index_transform/browser.py
284282
+++ b/index_transform/browser.py
285-
@@ -42,7 +42,7 @@ class Index2Browser(IndexTransform):
286-
283+
@@ -48,7 +48,7 @@ class Index2Browser(IndexTransform):
287284
res = u''
288-
res += '<tt><b>' + xml_escape(full_name) + '</b></tt> [<span class="link">'
289-
- res += '<a href="http://en.cppreference.com/w/' + xml_escape(full_link) + '">'
290-
+ res += '<a href="https://zh.cppreference.com/w/' + xml_escape(full_link) + '">'
291-
res += full_link + '</a></span>] <span class="mark">' + mark + '</span>\n'
292-
return res
293-
285+
res += '<tt><b>{0}</b></tt> [<span class="link">'.format(
286+
xml_escape(full_name))
287+
- res += '<a href="http://en.cppreference.com/w/{0}">'.format(
288+
+ res += '<a href="https://zh.cppreference.com/w/{0}">'.format(
289+
xml_escape(full_link))
290+
res += '{0}</a></span>] <span class="mark">{1}</span>\n'.format(
291+
full_link, mark)
294292
diff --git a/preprocess.py b/preprocess.py
295-
index 1a3b5c6..288fe0c 100755
293+
index a04abd2..95823b6 100755
296294
--- a/preprocess.py
297295
+++ b/preprocess.py
298-
@@ -29,12 +29,12 @@ def main():
299-
parser.add_argument('--dst', type=str, help='Destination folder to put preprocessed archive to')
296+
@@ -35,12 +35,12 @@ def main():
297+
help='Destination folder to put preprocessed archive to')
300298
args = parser.parse_args()
301299

302300
- root = args.dst
@@ -313,57 +311,25 @@ index 1a3b5c6..288fe0c 100755
313311
preprocess.rearrange_archive(root)
314312

315313
diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py
316-
index d4616aa..ef4de50 100644
314+
index 5233199..38ec845 100644
317315
--- a/tests/test_preprocess.py
318316
+++ b/tests/test_preprocess.py
319-
@@ -40,19 +40,26 @@ def nostdout():
320-
321-
class TestConvertLoaderName(unittest.TestCase):
322-
def test_convert_loader_name(self):
323-
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=scripts&skin=cppreference2&*'
324-
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
325-
+modules=site&only=scripts&skin=cppreference2&*'
326-
self.assertEqual('site_scripts.js', convert_loader_name(url))
327-
328-
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=styles&skin=cppreference2&*'
329-
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
330-
+modules=site&only=styles&skin=cppreference2&*'
331-
self.assertEqual('site_modules.css', convert_loader_name(url))
332-
333-
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
334-
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
335-
+modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
336-
self.assertEqual('skin_scripts.js', convert_loader_name(url))
337-
338-
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=startup&only=scripts&skin=cppreference2&*'
339-
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
340-
+modules=startup&only=scripts&skin=cppreference2&*'
341-
self.assertEqual('startup_scripts.js', convert_loader_name(url))
342-
343-
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=cppreference2&*'
344-
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
345-
+modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.\
346-
+legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=\
347-
+cppreference2&*'
348-
self.assertEqual('ext.css', convert_loader_name(url))
349-
350-
with self.assertRaises(Exception):
351-
@@ -227,7 +234,7 @@ class TestPreprocessHtml(unittest.TestCase):
352-
def setUp(self):
353-
self.testdata = os.path.join(os.path.dirname(__file__), 'preprocess_data')
317+
@@ -256,7 +256,7 @@ class TestPreprocessHtml(unittest.TestCase):
318+
self.testdata = os.path.join(os.path.dirname(__file__),
319+
'preprocess_data')
354320
infile = os.path.join(self.testdata, "fabs.html")
355321
- self.parser = etree.HTMLParser()
356322
+ self.parser = etree.HTMLParser(encoding="utf-8")
357323
self.html = etree.parse(infile, self.parser)
358324

359-
# Check whether the HTML matches the contents of the specified test data file
325+
# Check whether the HTML matches the contents of the specified test data
360326
diff --git a/tests/test_preprocess_cssless.py b/tests/test_preprocess_cssless.py
361-
index fc93019..ffad345 100644
327+
index 0b9f580..ab6dddb 100644
362328
--- a/tests/test_preprocess_cssless.py
363329
+++ b/tests/test_preprocess_cssless.py
364-
@@ -63,7 +63,7 @@ class HTMLTestBase(unittest.TestCase):
365-
input = '<html><body>{0}</body></html>'.format(input)
366-
expected_output = '<html><body>{0}</body></html>'.format(expected_output)
330+
@@ -81,7 +81,7 @@ class HTMLTestBase(unittest.TestCase):
331+
expected_output = \
332+
'<html><body>{0}</body></html>'.format(expected_output)
367333

368334
- parser = etree.HTMLParser()
369335
+ parser = etree.HTMLParser(encoding="utf-8")

0 commit comments

Comments
 (0)