You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/09/04 07:05:54 UTC
[incubator-echarts-doc] branch next updated: add patching between
different languages.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git
The following commit(s) were added to refs/heads/next by this push:
new f7d3775 add patching between different languages.
f7d3775 is described below
commit f7d37753f40a4c17199fd08cbcc965959066ed24
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Sep 4 15:05:37 2020 +0800
add patching between different languages.
---
README.md | 17 +++++++++++++++++
tool/format.js | 3 ++-
tool/patchLanguage.js | 15 ++++++++++++---
3 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index c20281e..61f56e5 100644
--- a/README.md
+++ b/README.md
@@ -97,6 +97,23 @@ Run
npm run format
```
+Make sure have a double review on the git diff after formatted.
+
+#### Sync docs between different languages.
+
+After you finished editing doc of one language. You can use following script to sync it to another language.
+
+```shell
+# zh to en
+node tool/patchLanguage --from=zh --to=en
+# en to zh
+node tool/patchLanguage --from=en --to=zh
+```
+
+Sync will move the structure. It will make editing of other languages much easier.
+
+Again make sure have a double review on the git diff after syncing.
+
#### Reference of option
A `~` can be used to refer to a option item in the same doc. For example:
diff --git a/tool/format.js b/tool/format.js
index eadef19..b0e96c3 100644
--- a/tool/format.js
+++ b/tool/format.js
@@ -10,6 +10,7 @@ const {parseBlocks} = require('../editor/common/parseBlocks');
(async function () {
for (let lang of ['en', 'zh']) {
const json = await parseBlocks(path.resolve(__dirname, `../${lang}/option`), true);
+ fs.writeFileSync(__dirname + `/blocks-${lang}.json`, JSON.stringify(json, null, 2), 'utf-8');
for (let fileName in json) {
const fileTargets = json[fileName];
const filePath = path.resolve(__dirname, `../${lang}/option/`, fileName.replace('.', '/')) + '.md';
@@ -19,4 +20,4 @@ const {parseBlocks} = require('../editor/common/parseBlocks');
fs.writeFileSync(filePath, fileContent, 'utf-8');
}
}
-})()
\ No newline at end of file
+})();
\ No newline at end of file
diff --git a/tool/patchLanguage.js b/tool/patchLanguage.js
index 09e16d9..01a203a 100644
--- a/tool/patchLanguage.js
+++ b/tool/patchLanguage.js
@@ -8,10 +8,12 @@ const {compositeTargets} = require('../editor/common/blockHelper');
const {parseBlocks} = require('../editor/common/parseBlocks');
const _ = require('lodash');
const arrayDiff = require('zrender/lib/core/arrayDiff2');
+const {argv} = require('yargs');
+const fromLang = argv.from || 'zh';
+const toLang = argv.to || 'en';
-const fromLang = 'zh';
-const toLang = 'en';
+console.log(`Patching from ${fromLang.toUpperCase()} to ${toLang.toUpperCase()}`);
function applyBlocksPatch(fromBlocks, toBlocks) {
const patchedBlocks = [];
@@ -22,6 +24,13 @@ function applyBlocksPatch(fromBlocks, toBlocks) {
for (let part of diffResult) {
if (part.removed) {
// Just ignore
+ for (let i = 0; i < part.indices.length; i++) {
+ const toBlock = toBlocks[part.indices[i]];
+ if (toBlock.type === 'uicontrol') {
+ // Not remove ui control block when patching from en to zh
+ patchedBlocks.push(_.clone(toBlock));
+ }
+ }
}
else {
for (let i = 0; i < part.indices.length; i++) {
@@ -29,7 +38,7 @@ function applyBlocksPatch(fromBlocks, toBlocks) {
// if (fromBlock.key === 'content:top.calendar.splitLine.lineStyle') {
// console.log(part);
// }
- // Just ignore uicontrol block.
+ // Ignore uicontrol block.
if (fromBlock.type === 'uicontrol') {
continue;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org