├── .gitignore
├── translate-js
├── config.json
├── util
│ └── writeJson.js
├── config
│ ├── defaultConfig.json
│ └── loggerConfig.js
├── src
│ ├── cutMdhead.js
│ ├── writeDataToFile.js
│ ├── readmd.js
│ ├── optionsTodo.js
│ ├── fixEntoZh.js
│ └── setObjectKey.js
├── CHANGELOG.md
├── index.test.js
├── md
│ ├── 2.zh.md
│ ├── about
│ │ ├── 3.zh.md
│ │ ├── 3.md
│ │ └── aboutme
│ │ │ ├── me.zh.md
│ │ │ └── me.md
│ ├── start
│ │ ├── index.zh.md
│ │ └── index.md
│ ├── 2.md
│ ├── 1.zh.md
│ └── 1.md
├── NodePathdata.json
├── test
│ ├── testWrite1.md
│ ├── testWrite1.zh.md
│ ├── testWrite3.md
│ ├── testWrite3.zh.md
│ ├── testWrite.md
│ ├── testWrite.zh.md
│ ├── writeDataToFile.test.js
│ ├── readmd.test.js
│ ├── fixEntoZh.test.js
│ ├── optionsTodo.test.js
│ ├── cutMdhead.test.js
│ ├── translateExports.test.js
│ ├── setObjectKey.test.js
│ └── setObjectKey.Object.js
├── .travis.yml
├── .gitignore
├── .vscode
│ └── launch.json
├── package.json
├── README.md
├── bin
│ └── translateExports.js
├── package-lock.json
├── index.js
└── License
├── try
├── try_remark.js
├── try_meow.js
└── try_tjs.js
├── package.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .DS_Store
--------------------------------------------------------------------------------
/translate-js/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "logger": {
3 | "level": "info"
4 | },
5 | "api": "baidu",
6 | "from": "en",
7 | "to": "zh",
8 | "num": 5,
9 | "rewrite": false
10 | }
--------------------------------------------------------------------------------
/translate-js/util/writeJson.js:
--------------------------------------------------------------------------------
1 | const fs = require('mz/fs')
2 | module.exports = async function writeJson(jsonFile, jsonObj) {
3 | await fs.writeFile(jsonFile, JSON.stringify(jsonObj, null, 2))
4 | }
--------------------------------------------------------------------------------
/translate-js/config/defaultConfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "logger": {
3 | "level": "info"
4 | },
5 | "api":"baidu",
6 | "from":"en",
7 | "to":"zh",
8 | "num": 5,
9 | "rewrite": false
10 | }
--------------------------------------------------------------------------------
/translate-js/src/cutMdhead.js:
--------------------------------------------------------------------------------
1 | module.exports = cutMdhead = (data) =>{
2 |
3 | if(data.startsWith('---')){
4 | let index = data.slice(3).indexOf('---') + 6
5 | return [data.slice(index), data.slice(0,index)]
6 |
7 | }
8 | return [data, ""]
9 | }
--------------------------------------------------------------------------------
/translate-js/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 2.5.4
2 | change output
3 | and -R rewrite cmd
4 |
5 | # 2.5.2 and 2.5.3
6 | fix bug
7 | # 2.5.1
8 |
9 | - add cli ``-f -t -a``
10 |
11 | - export options up ``aFile``, ``api``, ``tF``, ``tT``
12 | # 2.5.0
13 |
14 | - 文件夹 下 全 markdown 文件
15 | - 自动换 翻译源
--------------------------------------------------------------------------------
/translate-js/index.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const path = require('path')
3 | const execa = require('execa')
4 | process.chdir(path.resolve(__dirname));
5 |
6 | test('show help screen', async t => {
7 | t.regex(await execa.shell('node index.js').then(x=>x.stdout), /translate/)
8 | });
9 |
10 | test('show version', async t => {
11 | t.is(await execa.shell('node index.js --version').then(x=>x.stdout), require('./package').version);
12 | });
13 |
--------------------------------------------------------------------------------
/translate-js/config/loggerConfig.js:
--------------------------------------------------------------------------------
1 | var winston = require('winston');
2 |
3 | var logger = new (winston.Logger)({
4 | level:'info',
5 | transports: [
6 | new (winston.transports.Console)({datePattern: '.yyyy-MM-ddTHH-mm',colorize: true}),
7 | new (winston.transports.File)({ filename: 'translate-info.log' ,handleExceptions: true,
8 | maxsize: 52000, maxFiles: 1,level:'info',colorize: true}
9 | )
10 | ]
11 | });
12 |
13 | module.exports = {logger}
--------------------------------------------------------------------------------
/try/try_remark.js:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 lizhenyong
2 | //
3 | // This software is released under the MIT License.
4 | // https://opensource.org/licenses/MIT
5 |
6 | var remark = require('remark');
7 |
8 | var body = `# Hello`
9 |
10 | var mdAst = remark.parse(body)
11 |
12 | console.log('语法树 var mdAst = remark.parse(body) *****\n\n mdAst=',mdAst)
13 |
14 | var reBody = remark.stringify(mdAst)
15 |
16 | console.log('\n\n变回来 var reBody = remark.stringify(mdAst) ****\n\n reBody=',reBody)
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/try/try_meow.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | 'use strict';
3 | const meow = require('meow');
4 |
5 | const cli = meow(`
6 | Usage
7 | $ example
8 |
9 | Options
10 | --rainbow, -r Include a rainbow
11 |
12 | Examples
13 | $ foo unicorns --rainbow
14 | 🌈 unicorns 🌈
15 | `, {
16 | flags: {
17 | rainbow: {
18 | type: 'boolean',
19 | alias: 'r'
20 | }
21 | }
22 | });
23 | /*
24 | {
25 | input: ['unicorns'],
26 | flags: {rainbow: true},
27 | ...
28 | }
29 | */
30 | console.log(cli.help)
31 | console.log(cli.input[0], cli.flags);
--------------------------------------------------------------------------------
/try/try_tjs.js:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017 lizhenyong
2 | //
3 | // This software is released under the MIT License.
4 | // https://opensource.org/licenses/MIT
5 | (async function(){
6 | const tjs = require('translation.js')
7 |
8 | let thisTranString = "hello world"
9 | let api = "baidu"
10 | let tranF = "en"
11 | let tranT = "zh"
12 | let result = await tjs.translate({
13 | text: thisTranString,
14 | api: api,
15 | from: tranF,
16 | to: tranT
17 | })
18 | console.log(result.result)
19 | }
20 | )()
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "explain-translatemds",
3 | "version": "1.0.0",
4 | "description": "explain translate-mds project",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "ava -v -s",
8 | "tjs:try": "node try/try_tjs.js",
9 | "meow:try": "node try/try_meow.js Helloworld",
10 | "emark:try": "node try/try_remark.js",
11 | "lint:myChinaSynbal": "hint README.md"
12 | },
13 | "keywords": [
14 | "explain",
15 | "translate-mds"
16 | ],
17 | "author": "yobrave",
18 | "license": "MIT",
19 | "dependencies": {
20 | "meow": "^4.0.0",
21 | "remark": "^8.0.0",
22 | "translation.js": "^0.6.4"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/translate-js/md/2.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | 雨果是**世界上最快的静态网站引擎. **它是用去(aka Golang)开发的[BEP](https://github.com/bep),[spf13](https://github.com/spf13)和[朋友](https://github.com/gohugoio/hugo/graphs/contributors). 下面您将从我们的文档中找到一些最常见和最有用的页面.
20 |
21 | 你好
22 |
--------------------------------------------------------------------------------
/translate-js/md/about/3.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | 雨果是**世界上最快的静态网站引擎. **它是用去(aka Golang)开发的[BEP](https://github.com/bep),[spf13](https://github.com/spf13)和[朋友](https://github.com/gohugoio/hugo/graphs/contributors). 下面您将从我们的文档中找到一些最常见和最有用的页面.
20 |
21 | 你好
22 |
--------------------------------------------------------------------------------
/translate-js/md/start/index.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | 雨果是**世界上最快的静态网站引擎. **它是用去(aka Golang)开发的[BEP](https://github.com/bep),[spf13](https://github.com/spf13)和[朋友](https://github.com/gohugoio/hugo/graphs/contributors). 下面您将从我们的文档中找到一些最常见和最有用的页面.
20 |
21 | 你好
22 |
--------------------------------------------------------------------------------
/translate-js/NodePathdata.json:
--------------------------------------------------------------------------------
1 | {
2 | "/Users/lizhenyong/Desktop/JSJSJSJSJSJJSJS——project/translate-js/index.js": [
3 | "node_modules/translation.js/libs/index.js",
4 | "src/readmd.js",
5 | "node_modules/meow/index.js",
6 | "node_modules/chalk/index.js",
7 | "src/cutMdhead.js",
8 | "node_modules/_remark@8.0.0@remark/index.js",
9 | "src/optionsTodo.js",
10 | "config/loggerConfig.js",
11 | "config/defaultConfig.json",
12 | "util/writeJson.js"
13 | ],
14 | "/Users/lizhenyong/Desktop/JSJSJSJSJSJJSJS——project/translate-js/src/readmd.js": [
15 | "../node_modules/mz/fs.js"
16 | ],
17 | "/Users/lizhenyong/Desktop/JSJSJSJSJSJJSJS——project/translate-js/config/loggerConfig.js": [
18 | "../node_modules/_winston@2.4.0@winston/lib/winston.js"
19 | ]
20 | }
--------------------------------------------------------------------------------
/translate-js/md/2.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
20 |
21 | 你好
--------------------------------------------------------------------------------
/translate-js/test/testWrite1.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
--------------------------------------------------------------------------------
/translate-js/test/testWrite1.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
--------------------------------------------------------------------------------
/translate-js/test/testWrite3.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
--------------------------------------------------------------------------------
/translate-js/test/testWrite3.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
--------------------------------------------------------------------------------
/translate-js/md/about/3.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
20 |
21 | 你好
--------------------------------------------------------------------------------
/translate-js/md/start/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
20 |
21 | 你好
--------------------------------------------------------------------------------
/translate-js/test/testWrite.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
20 | ➜ /Users/lizhenyong/Desk
--------------------------------------------------------------------------------
/translate-js/test/testWrite.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hugo Documentation
3 | linktitle: Hugo
4 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | menu:
9 | main:
10 | parent: "section name"
11 | weight: 01
12 | weight: 01 #rem
13 | draft: false
14 | slug:
15 | aliases: []
16 | toc: false
17 | layout: documentation-home
18 | ---
19 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
20 | ➜ /Users/lizhenyong/Desk
--------------------------------------------------------------------------------
/translate-js/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 8.0.0
4 | - 8.1.1
5 | - 8.5.0
6 | script:
7 | - npm test
8 | after_success:
9 | - bash <(curl -s https://codecov.io/bash)
10 | deploy:
11 | provider: npm
12 | email: yobrave@outlook.com
13 | api_key:
14 | secure: ZBbhBBFZ0mOvIhuXZwmK87h7JnwPAkEP88qaBx7jELHdos0r7O7G0F6Tb+Zfw7UWM2aJPXrMthH28rsbpr3zGX0Y3qD5VmfyeGWSZd+UimEmEYpQpJ1rilpynkMLpbBeultapN1bN4ZWGwDYsyoXNC4Y/lfleq+ZKE0O80oBqu8M1EXN1QJrCnV7lIz7R+FRk/EP3jo0LZ0ZBAWuhSbJ4JWzliD41NCJVanoT1qj//3+NXEgKCOPc2lvG31AhYDCj0C0/34MY1woS8laVEY5qA3fGUljktob2edcv1+VThZ8rP7yYKiKVmdd6mJpkDEBxAm8zR1FKg19Il1wo/20F2e/41wcaHch8WNXJWHXSaduXzK2VE5obsRTkwWL5WRddmdSsRuL3yu8W79wrMEh48oJXWHEP05dDAPxr7tmjEJke68fIOjdeAERU3V7hgSohjEgHLDRG1O7OskFX+FuUC5tDh+fYjVF0LgduR8OyLspXZgBwy2+Z0GyGaIhgVMGPsxZJkenXC0G8YMqzbqdakfBtEQrW8zXMSfa+FcsdbxnU6DW/BWNUFVCRfiabE453YuWh2/KzVSGKXmtIqqNkZpicDeZwsA691Ci6QwOIEx1ISo+aN8gCYO/U4PoSLDYfKxZvoBLNtvi/RNQxfAN9j0kIL3MRmKU3Fok0MsRNDI=
15 | on:
16 | branch: master
17 | tags: true
18 | repo: chinanf-boy/translate-js
19 |
--------------------------------------------------------------------------------
/translate-js/.gitignore:
--------------------------------------------------------------------------------
1 | *DS
2 | node_modules/
3 | .nyc_ou*
4 | *.log
5 | npm-debug.log*
6 |
7 | # vscode debug
8 | try.js
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 |
15 | # Directory for instrumented libs generated by jscoverage/JSCover
16 | lib-cov
17 |
18 | # Coverage directory used by tools like istanbul
19 | coverage
20 |
21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22 | .grunt
23 |
24 | # node-waf configuration
25 | .lock-wscript
26 |
27 | # Compiled binary addons (http://nodejs.org/api/addons.html)
28 | build/*
29 |
30 | # Dependency directory
31 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
32 | node_modules
33 |
34 | # Static file
35 | public
36 |
37 | # Bower
38 | bower_components
39 |
40 | # Optional npm cache directory
41 | .npm
42 |
43 | # Optional REPL history
44 | .node_repl_history
45 |
46 | .idea/*
47 | yarn.lock
48 | /coverage
49 | .DS_Store
50 | src/config/config.local*
51 | src/config/sequelize.json
52 | lib/*
53 | .nyc_output
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 lizhenyong-yobrave
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/translate-js/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // 使用 IntelliSense 了解相关属性。
3 | // 悬停以查看现有属性的描述。
4 | // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch try export",
11 | "program": "${workspaceFolder}/try.js"
12 | },
13 | {
14 | "type": "node",
15 | "request": "launch",
16 | "name": "Launch src/write",
17 | "program": "${workspaceFolder}/src/writeDataToFile.js"
18 | },
19 | {
20 | "type": "node",
21 | "request": "launch",
22 | "name": "Launch src/readmd",
23 | "program": "${workspaceFolder}/src/readmd.js"
24 | },
25 | {
26 | "type": "node",
27 | "request": "launch",
28 | "name": "Launch index",
29 | "program": "${workspaceFolder}/index.js",
30 | "args": [
31 | "test/testWrite.md"
32 | ]
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/translate-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "translate-mds",
3 | "version": "2.5.6",
4 | "description": "translate [folder] md file language to you want",
5 | "main": "./bin/translateExports.js",
6 | "engines": {
7 | "node": ">=8.0.0"
8 | },
9 | "scripts": {
10 | "demo": "node index.js md/",
11 | "ava": "ava --verbose --serial",
12 | "test": "nyc --reporter=lcov --reporter=text --reporter=html npm run ava",
13 | "pubGitandNpm": "git push origin master && git push --tags"
14 | },
15 | "ava": {
16 | "files": [
17 | "test/**/*",
18 | "!test/*.Object.js",
19 | "!config.js",
20 | "!index.js"
21 | ]
22 | },
23 | "bin": {
24 | "translateMds": "./index.js"
25 | },
26 | "author": "yobrave",
27 | "license": "ISC",
28 | "dependencies": {
29 | "async": "^2.6.0",
30 | "chalk": "^2.3.0",
31 | "meow": "^3.7.0",
32 | "mz": "^2.7.0",
33 | "ora": "^1.3.0",
34 | "remark": "^8.0.0",
35 | "translation.js": "^0.6.4",
36 | "winston": "^2.4.0"
37 | },
38 | "keywords": [
39 | "md",
40 | "translate"
41 | ],
42 | "devDependencies": {
43 | "ava": "^0.24.0",
44 | "nyc": "^11.3.0"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/translate-js/test/writeDataToFile.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const fs = require('fs')
3 |
4 | const { writeDataToFile, insert_flg } = require('../src/writeDataToFile.js')
5 |
6 | test("get new filename ",t =>{
7 | let result = insert_flg('aaaa.md', '.zh', 3)
8 | t.is(result, 'aaaa.zh.md')
9 | })
10 |
11 | test.failing("get bad filename ",t =>{
12 | insert_flg('', '.zh', 3)
13 | t.fail('这里是传入不正确的文件名')
14 | })
15 |
16 | test.cb("write data to zh", t =>{
17 |
18 | fs.readFile(__dirname + '/testWrite3.md', 'utf8', (err, data) =>{
19 | if (err) throw err;
20 | writeDataToFile(data, __dirname + '/testWrite3.md')
21 |
22 | fs.readFile(__dirname + '/testWrite3.zh.md', 'utf8', (err, insidedata) =>{
23 | if (err) throw err;
24 | t.is(insidedata, data)
25 | t.end()
26 | });
27 | });
28 | })
29 |
30 | test("filename no .md", t =>{
31 | let result = writeDataToFile('data', __dirname + '')
32 | t.false(result)
33 | })
34 |
35 | test.failing("filename Array ", t =>{
36 | let result = writeDataToFile(['data','data'], __dirname + '')
37 | t.fail("no md file")
38 | })
39 |
--------------------------------------------------------------------------------
/translate-js/src/writeDataToFile.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs')
2 | const { fixEntoZh } = require('./fixEntoZh')
3 | const chalk = require('chalk');
4 | const { logger } = require('../config/loggerConfig.js')
5 | const configs = require('../config.json')
6 | const tranT = configs.to
7 | function insert_flg(str, flg, Uindex) {
8 | var newstr = "";
9 | if(!str || !flg){
10 | throw logger.error('filename<',str,'>can not add',flg)
11 | }
12 | var len = str.length
13 | var tmp = str.substring(0, len - Uindex);
14 | newstr = tmp + flg + str.substring(len-Uindex, len)
15 | return newstr;
16 | }
17 |
18 | const writeDataToFile = (data, file_dir) => {
19 | var zhfile
20 | if(!file_dir.endsWith('.md')){
21 | logger.verbose(file_dir,chalk.green('no md file,just go away'))
22 | return false
23 | }
24 | zhfile = insert_flg(file_dir, `.${tranT}`, 3)
25 |
26 | // data is Array
27 | //fixE2Z
28 |
29 | if(data instanceof Array){
30 | data = fixEntoZh(data).join("\n")
31 | }
32 |
33 |
34 | fs.writeFile(zhfile+'', data, (err) => {
35 | if (err)
36 | throw err;
37 | logger.log('debug',chalk.magenta( `\n ${tranT} file saved! -->> \n`),chalk.blue(zhfile));
38 | logger.debug(chalk.red('translate-info.log in your Project'))
39 | });
40 | }
41 |
42 | module.exports = {writeDataToFile, insert_flg}
--------------------------------------------------------------------------------
/translate-js/src/readmd.js:
--------------------------------------------------------------------------------
1 | const fs = require('mz/fs')
2 | const path = require('path')
3 |
4 | const readMdir = async (Dir) =>{
5 |
6 |
7 | var dirlist = await fs.readdir(Dir, 'utf8').then( files => files).catch(err => err)
8 | return dirlist
9 | }
10 |
11 | function unique5(array){ var r = []; for(var i = 0, l = array.length; i < l; i++) { for(var j = i + 1; j < l; j++) if (array[i] === array[j]) j = ++i; r.push(array[i]); } return r; }
12 |
13 | const Listmd = async (contentDir, output = []) =>{
14 | var input = []
15 |
16 | if( await fs.lstat(contentDir).then(x =>x.isFile())){
17 | input.push(path.basename(contentDir))
18 | contentDir = path.dirname(contentDir)
19 | }
20 | else{
21 | if( ! contentDir.endsWith('/') ){
22 | contentDir += '/'
23 | }
24 | input = await readMdir(contentDir)
25 | }
26 |
27 | if (input instanceof Error)
28 | return Promise.reject(input)
29 |
30 | while ( input.length ){
31 | let path_string = input.shift()
32 | if(await fs.lstat( path.join(contentDir,path_string)).then(x =>x.isDirectory())){
33 |
34 | await Listmd(path.join(contentDir, path_string), output)
35 |
36 | }else{
37 | output.push(path.join(contentDir, path_string))
38 | }
39 | }
40 |
41 |
42 | return Promise.resolve( output )
43 |
44 | }
45 |
46 | module.exports = {Listmd, unique5};
--------------------------------------------------------------------------------
/translate-js/test/readmd.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 |
3 | const {Listmd, unique5} = require('../src/readmd.js')
4 |
5 |
6 | test("read zh md folder", async t =>{
7 | const len = await Listmd(__dirname+"/../md/").then(x => x)
8 |
9 | t.is(len.length, 10)
10 | })
11 |
12 | test("read md no / folder", async t =>{
13 | const len = await Listmd(__dirname+"/../md").then(x => x)
14 | t.is(len.length, 10)
15 | })
16 |
17 | test("read no absolute dir", async t =>{
18 | const E = await Listmd("/../md").then(x => x).catch(x =>x)
19 | t.true(E instanceof Error)
20 | })
21 |
22 | test.serial.before("read md file", async t =>{
23 | const len = await Listmd(__dirname+"/testWrite.md").then(x => x)
24 |
25 |
26 | t.is(len.length, 1)
27 |
28 |
29 | })
30 |
31 | // test.serial.before("read md no /", async t =>{
32 |
33 | // const len2 = await Listmd(__dirname+"/../md").then(x => x)
34 | // t.is(len2.length, 5)
35 | // })
36 |
37 | test("read md no Dir ",async t =>{
38 |
39 | const error = await Listmd("/../md/").catch(x => x)
40 |
41 | t.true(error instanceof Error)
42 | })
43 |
44 | test(" array 去掉重复", t =>{
45 | var a = [1,2,3,4,5,6]
46 | var b = ['a','b','c','d']
47 |
48 | const new_b = unique5(Array.from(b+b))
49 | const new_a = unique5(Array.from(a+a))
50 |
51 | t.is(new_a.length,['1','2','3','4','5','6',','].length)
52 | t.is(new_b.length,["a","b","d","c",","].length)
53 |
54 | })
--------------------------------------------------------------------------------
/translate-js/test/fixEntoZh.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const fs = require('fs')
3 |
4 | const { fixEntoZh, charZh2En, reg, Store, halfStr ,reg2 } = require('../src/fixEntoZh.js')
5 |
6 | test("fix EntoZh 二分法 分离 字符串", t =>{
7 | let result = fixEntoZh("你好阿baby'‘~`!@“#$^")
8 |
9 | t.is(result,"你好阿baby''~`!@\"#$^")
10 | })
11 |
12 | test("fix EntoZh 二分法 分离 字符串 Array", t =>{
13 | let result = fixEntoZh(["你好阿baby'‘~`","!@“#$^"])
14 | t.deepEqual(result,["你好阿baby''~`","!@\"#$^"])
15 | })
16 |
17 | test("二分法 分离 字符串", t =>{
18 | let result = halfStr("你好阿baby'‘~`!@“#$^")
19 |
20 | t.is(result,"你好阿baby''~`!@\"#$^")
21 | })
22 |
23 | test("中文符号", t =>{
24 |
25 | t.true(reg2("@#$^%&*("))
26 |
27 | })
28 |
29 | test("是不是有中文符号", t =>{
30 |
31 | t.true(reg.test("~`!@#$^%&*()_+|-={}[]ℴ:“‘;<>?,./\'"))
32 |
33 | })
34 |
35 | test("特别 中文 单双引号", t =>{
36 |
37 | let re = Object.keys(Store)
38 |
39 | t.is(Store[re[0]],'"')
40 | t.is(Store[re[1]],'\'')
41 |
42 | })
43 |
44 | test(" 中文符号 变 英文符号 ",t =>{
45 | let result = charZh2En("~`!@#$^%&*()_+|-={}[]:“‘;<>?,./\'")
46 | t.is(result, "~`!@#$^%&*()_+|-={}[]: \"';<>?,./\\'")
47 |
48 | let re = charZh2En("#")
49 | t.is(re, "#")
50 |
51 | })
52 |
53 | test("me.md E 2 Z 不管 中文字 ", t =>{
54 | let result = charZh2En(`---
55 | 标题:雨果文档
56 | linktitle:雨果
57 | 描述:雨果是世界上最快的静态网站引擎。它是用去(aka Golang)研制的BEP,spf13和朋友。
58 | 日期:2017-02-01
59 | publishdate:2017-02-01
60 | lastmod:2017-02-01`)
61 |
62 | t.false(reg.test(result))
63 |
64 | })
65 |
--------------------------------------------------------------------------------
/translate-js/test/optionsTodo.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const fs = require('fs')
3 | let p = '../src/optionsTodo.js'
4 | const defaultArgs = {
5 | "logger": {
6 | "level": "verbose"
7 | },
8 | "api":"baidu",
9 | "from":"en",
10 | "to":"zh",
11 | "num": 5,
12 | "rewrite": false
13 | }
14 | const {setDefault} = require(p)
15 |
16 | const rNobj =(obj) =>JSON.parse(JSON.stringify(obj))
17 |
18 | test("setDefault",t=>{
19 | function sum(a,b){return a+b}
20 | const s = setDefault(1, sum, 1)
21 | t.is(s,2)
22 | })
23 |
24 | const {debugTodo} = require(p)
25 |
26 | test("debugTodo",t=>{
27 | const s = debugTodo(true,rNobj(defaultArgs))
28 | t.is(s, 'debug')
29 | const s2 = debugTodo('info',rNobj(defaultArgs))
30 | t.is(s2,'info')
31 | })
32 |
33 | const {fromTodo} = require(p)
34 |
35 | test("fromTodo",t=>{
36 | const s = fromTodo('zh',rNobj(defaultArgs))
37 | t.is(s,'zh')
38 | const s2 = fromTodo('',rNobj(defaultArgs))
39 | t.is(s2,'en')
40 | })
41 | const {toTodo} = require(p)
42 |
43 | test("toTodo",t=>{
44 | const s = toTodo('ja',rNobj(defaultArgs))
45 | t.is(s,'ja')
46 | const s2 = toTodo('',rNobj(defaultArgs))
47 | t.is(s2,'zh')
48 | })
49 | const {apiTodo} = require(p)
50 |
51 | test("apiTodo",t=>{
52 | const s = apiTodo('',rNobj(defaultArgs))
53 | t.is(s,'baidu')
54 | const s2 = apiTodo('google',rNobj(defaultArgs))
55 | t.is(s2,'google')
56 | })
57 | const {rewriteTodo} = require(p)
58 |
59 | test("rewriteTodo",t=>{
60 | const one = rewriteTodo(true,rNobj(defaultArgs))
61 | t.is(one,true)
62 |
63 | const two = rewriteTodo('google',rNobj(defaultArgs))
64 | t.is(two,true)
65 |
66 | const three = rewriteTodo('',rNobj(defaultArgs))
67 | t.is(three,false)
68 | })
69 | const {numTodo} = require(p)
70 |
71 | test("numTodo",t=>{
72 | const s = numTodo(10,rNobj(defaultArgs))
73 | t.is(s,10)
74 |
75 | const s2 = numTodo('google',rNobj(defaultArgs))
76 | t.is(s2,5)
77 | })
--------------------------------------------------------------------------------
/translate-js/src/optionsTodo.js:
--------------------------------------------------------------------------------
1 |
2 | // defaultConfig options
3 | /**
4 | * @description
5 | * @param {String|Boolean} option
6 | * @param {Function} callback
7 | * @param {any} args
8 | * @returns {Function}
9 | */
10 | function setDefault(option, callback, args){
11 | return callback(option, args)
12 | }
13 |
14 | /**
15 | * @description
16 | * @param {String|Boolean} debug
17 | * @param {any} args
18 | * @returns {String}
19 | */
20 | function debugTodo(debug, args){
21 | if(debug){
22 | args.logger.level = 'debug'
23 | }
24 | if(typeof debug == 'string'){
25 | args.logger.level = debug
26 | }
27 | return args.logger.level
28 | }
29 |
30 | /**
31 | * @description
32 | * @param {String} tranFrom
33 | * @param {any} args
34 | * @returns {String}
35 | */
36 | function fromTodo(tranFrom, args){
37 | if(tranFrom){
38 | args.from = tranFrom
39 | }
40 | return args.from
41 | }
42 |
43 | /**
44 | * @description
45 | * @param {String} tranTo
46 | * @param {any} args
47 | * @returns {String}
48 | */
49 | function toTodo(tranTo, args){
50 | if(tranTo){
51 | args.to = tranTo
52 | }
53 | return args.to
54 | }
55 |
56 | /**
57 | * @description
58 | * @param {number} num
59 | * @param {any} args
60 | * @returns {number}
61 | */
62 | function numTodo(num, args){
63 | if(typeof num == 'number'){
64 | if(num > 0){
65 | args.num = num
66 | }
67 | }
68 | return args.num
69 | }
70 |
71 | /**
72 | * @description api {``baidu | google | youdao``}
73 | * @param {String} api
74 | * @param {any} args
75 | * @returns {String}
76 | */
77 | function apiTodo(api, args){
78 | if(api){
79 | args.api = api
80 |
81 | }
82 | return args.api
83 | }
84 |
85 | /**
86 | * @description
87 | * @param {Boolean} rewrite
88 | * @param {any} args
89 | * @returns {Boolean}
90 | */
91 | function rewriteTodo(rewrite, args) {
92 |
93 | args.rewrite = rewrite? true : false
94 | return args.rewrite
95 | }
96 | module.exports = {setDefault, debugTodo, fromTodo, toTodo, apiTodo, rewriteTodo, numTodo }
97 |
--------------------------------------------------------------------------------
/translate-js/test/cutMdhead.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const fs = require('fs')
3 |
4 | const cut = require('../src/cutMdhead.js')
5 |
6 | test("cut md head", t =>{
7 | let [body, head] = cut(beforedata)
8 | t.is(body, afterdata)
9 | t.is(head, onlyhead)
10 | })
11 |
12 | test(" no cut ", t =>{
13 | let [body, head] = cut("# 你好")
14 | t.is(body,"# 你好")
15 | t.is(head, "")
16 | })
17 |
18 | let onlyhead = `---
19 | title: Hugo Documentation
20 | linktitle: Hugo
21 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
22 | date: 2017-02-01
23 | publishdate: 2017-02-01
24 | lastmod: 2017-02-01
25 | menu:
26 | main:
27 | parent: "section name"
28 | weight: 01
29 | weight: 01 #rem
30 | draft: false
31 | slug:
32 | aliases: []
33 | toc: false
34 | layout: documentation-home
35 | ---`
36 |
37 | let afterdata = `
38 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
39 | ➜ /Users/lizhenyong/Desk`
40 |
41 | let beforedata = `---
42 | title: Hugo Documentation
43 | linktitle: Hugo
44 | description: Hugo is the world's fastest static website engine. It's written in Go (aka Golang) and developed by bep, spf13 and friends.
45 | date: 2017-02-01
46 | publishdate: 2017-02-01
47 | lastmod: 2017-02-01
48 | menu:
49 | main:
50 | parent: "section name"
51 | weight: 01
52 | weight: 01 #rem
53 | draft: false
54 | slug:
55 | aliases: []
56 | toc: false
57 | layout: documentation-home
58 | ---
59 | Hugo is the **world's fastest static website engine.** It's written in Go (aka Golang) and developed by [bep](https://github.com/bep), [spf13](https://github.com/spf13) and [friends](https://github.com/gohugoio/hugo/graphs/contributors). Below you will find some of the most common and helpful pages from our documentation.
60 | ➜ /Users/lizhenyong/Desk`
--------------------------------------------------------------------------------
/translate-js/src/fixEntoZh.js:
--------------------------------------------------------------------------------
1 | const Store = {
2 | // 第一优先级
3 | '“': '"',
4 | "‘": "'",
5 | ":": ": ",
6 | "/ ": "/",
7 | "ℴ": "-",
8 | "”": '"',
9 | "。": ". "
10 |
11 | }
12 |
13 | // 二分法 获取
14 | /**
15 | * @description
16 | * @param {String} str
17 | * @returns {String}
18 | */
19 | const halfStr = (str) =>{
20 | if (str.length <= 1 ) {
21 | if(reg.test(str) || reg2(str)){
22 | return charZh2En(str)
23 | }
24 | return str
25 | }
26 |
27 | let qian = str.substring(0, str.length/2)
28 | let hou = str.substring(str.length/2, str.length)
29 |
30 | return halfStr(qian) + halfStr(hou)
31 | }
32 |
33 | // 验证 1
34 | const reg = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
35 |
36 | // 验证 2
37 | const reg2 = (str) => {
38 | for(i in str){
39 | if( "~`!@#$^%&*()_+|-={}[]:";<>?,./\'".indexOf(str[i])>=0 ){
40 | return true
41 | }
42 | }
43 | return false
44 | }
45 |
46 | const numStore = [8220, 8216]
47 |
48 | // , 34, 39
49 | // 执行 转化操作
50 | function charZh2En(str) {
51 | var tmp = '';
52 | for (var i = 0; i < str.length; i++) {
53 | if( Object.keys(Store).some(x =>x==str[i])){
54 | // 第一优先级
55 | tmp += Store[str[i]]
56 | }else{
57 | // 第二优先级
58 | tmp += String.fromCharCode(str.charCodeAt(i) - 65248)
59 | }
60 | }
61 | return tmp
62 | }
63 |
64 | // 主 函数
65 | /**
66 | * @description
67 | * @param {Array|String} data
68 | * @returns {Array|String}
69 | */
70 | const fixEntoZh = function fixEntoZh(data){
71 |
72 | if(!(data instanceof Array)){
73 | data = data.trim()
74 | return halfStr(data)
75 | }else{
76 |
77 | data = data.map(x =>{
78 | return halfStr(x)
79 | })
80 |
81 | return data
82 | }
83 |
84 | }
85 |
86 | module.exports = {fixEntoZh, charZh2En ,reg, Store, halfStr, reg2 }
87 |
88 |
--------------------------------------------------------------------------------
/translate-js/test/translateExports.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const path = require('path')
3 | const translate = require('../bin/translateExports.js')
4 |
5 | let trueResult = `---\ntitle: Hugo Documentation\nlinktitle: Hugo\ndescription: Hugo is the world\'s fastest static website engine. It\'s written in Go (aka Golang) and developed by bep, spf13 and friends.\ndate: 2017-02-01\npublishdate: 2017-02-01\nlastmod: 2017-02-01\nmenu:\n main:\n parent: \"section name\"\n weight: 01\nweight: 01\t#rem\ndraft: false\nslug:\naliases: []\ntoc: false\nlayout: documentation-home\n---\n雨果是**世界上最快的静态网站引擎。**它是用去(aka Golang)开发的[BEP](https://github.com/bep),[spf13](https://github.com/spf13)和[朋友](https://github.com/gohugoio/hugo/graphs/contributors)。下面您将从我们的文档中找到一些最常见和最有用的页面。\n`
6 |
7 | test.failing('translate no absolute file fail', async t =>{
8 | let results = await translate(['./testWrite1.md'])
9 | t.fail()
10 | })
11 |
12 | test.failing('translate nothing', async t =>{
13 | let results = await translate("")
14 | t.fail()
15 | })
16 | test.failing('translate input Object fail', async t =>{
17 | let results = await translate({})
18 | t.fail()
19 | })
20 | test.serial('translate absolute file ', async t =>{
21 | let results = await translate({aFile:__dirname+'/testWrite1.md', api:'baidu'})
22 | results = results.join('\n')
23 | t.is(JSON.stringify(results), JSON.stringify(trueResult))
24 | })
25 |
26 | test.serial('translate absolute file from zh to en', async t =>{
27 | let results = await translate({'aFile':__dirname+'/testWrite1.md',tF:'en',tT:'zh'})
28 | t.is(results.length, 1)
29 | })
30 |
31 | test.serial('translate absolute folder auto', async t =>{
32 | let results = await translate([path.resolve(__dirname,'../md/'),'baidu'], 'info')
33 | t.is(results.length,5)
34 | })
35 |
36 | // test.serial('translate absolute big folder auto', async t =>{
37 | // let results = await translate([`*******/You_Don\'t\ _Know_JS/You-Dont-Know-JS`,'baidu'], 'verbose')
38 | // t.is(results.length,5)
39 | // })
40 | // test async translate
41 | // while del serial , config.json is error
42 | // before data
43 | // {
44 | // "from": "en",
45 | // "to": "zh"
46 | // }
47 | // other write data
48 | // {
49 | // "from": "en",
50 | // "to": "zh",
51 | // "t": "1"
52 | // }
53 | // Data json show
54 | // {
55 | // "from": "en",
56 | // "to": "zh"
57 | // }" // other write here is not emtpy
58 | // }
--------------------------------------------------------------------------------
/translate-js/md/1.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Accented Characters in URLs
3 | linktitle: Accented Characters in URLs
4 | description: If you're having trouble with special characters in your taxonomies or titles adding odd characters to your URLs.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | keywords: [urls,multilingual,special characters]
9 | categories: [troubleshooting]
10 | menu:
11 | docs:
12 | parent: "troubleshooting"
13 | weight:
14 | draft: false
15 | slug:
16 | aliases: [/troubleshooting/categories-with-accented-characters/]
17 | toc: true
18 | ---
19 | ## 问题: 带有重音字符的类别
20 |
21 | > 我的一个类别被命名为"乐卡尔",但链接最终是这样生成的:
22 | >
23 | > categories/le-carr%C3%A9
24 | >
25 | > 不工作. 我能忽略这个问题吗?
26 |
27 | ## 解决方案
28 |
29 | 你是一个MacOS的用户吗?如果是这样的话,你可能是一个受害者,HFS +文件系统的坚持来存储"é"(U + 00e9)字符正常形式分解(NFD)模式,即为"E"+"́"(U + 0065 + 0301).
30 |
31 | `勒% %`实际上是正确的,`% %`在U+ UTF-8版本00e9预期由Web服务器. 问题是OS X转了. [u + 00e9]进入之内[0065+0301+],从而`勒% %`不再工作. 相反,只有`勒卡雷连铸% 81`结束`81 %`将匹配[0065+0301+]最后.
32 |
33 | 这是OS X独有的. 世界上其他地方没有这样做,当然也不是你最可能运行Linux的Web服务器. 这也不是雨果特有的问题. 其他人在他们的HTML文件中有重音字符时就被这个咬了.
34 |
35 | 注意,这个问题并不具体于拉丁语脚本. 日本的Mac用户经常遇到相同的问题,例如`だ`分解成`た`和`与# x3099;`. (读[日本perl用户文章][]).
36 |
37 | rsync 3. x的救援!从[服务器故障的答案][]:
38 |
39 | > 你可以使用rsync的`ℴℴiconv`选择UTF-8 NFC与NFD之间转换,至少如果你的Mac. 有一个特别的`utf-8-mac`字符集是UTF-8 NFD. 因此,为了将文件从Mac复制到Web服务器,您需要运行类似于:
40 | >
41 | > `rsync -ℴℴiconv = utf-8-mac,UTF-8 localdir / mywebserver: remotedir /`
42 | >
43 | > 这会将所有本地文件名由UTF-8 NFD为NFC在远程服务器. 文件的内容不会受到影响. ℴ[服务器故障][]
44 |
45 | 请确保你有rsync 3的最新版本. 装X. rsync,OS X的船只已经过时. 即使是包装版本10.10(优诗美地国家公园)是版本2.6.9协议版本29. 这个`ℴℴiconv`国旗是新的rsync 3. X.
46 |
47 | ### 论坛参考
48 |
49 | -
50 | - [http://wiki.apache.org/subversion/nonnormalizingunicodecompositionawareness](http://wiki.apache.org/subversion/NonNormalizingUnicodeCompositionAwareness)
51 | - [http: / /恩. 维基百科. org /维基/ unicode_equivalence #例子](https://en.wikipedia.org/wiki/Unicode_equivalence#Example)
52 | -
53 | -
54 |
55 | [an answer posted on server fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
56 |
57 | [japanese perl users article]: http://perl-users.jp/articles/advent-calendar/2010/english/24 "Encode::UTF8Mac makes you happy while handling file names on MacOSX"
58 |
59 | [server fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
60 |
--------------------------------------------------------------------------------
/translate-js/md/about/aboutme/me.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Accented Characters in URLs
3 | linktitle: Accented Characters in URLs
4 | description: If you're having trouble with special characters in your taxonomies or titles adding odd characters to your URLs.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | keywords: [urls,multilingual,special characters]
9 | categories: [troubleshooting]
10 | menu:
11 | docs:
12 | parent: "troubleshooting"
13 | weight:
14 | draft: false
15 | slug:
16 | aliases: [/troubleshooting/categories-with-accented-characters/]
17 | toc: true
18 | ---
19 | ## 问题: 带有重音字符的类别
20 |
21 | > 我的一个类别被命名为"乐卡尔",但链接最终是这样生成的:
22 | >
23 | > categories/le-carr%C3%A9
24 | >
25 | > 不工作. 我能忽略这个问题吗?
26 |
27 | ## 解决方案
28 |
29 | 你是一个MacOS的用户吗?如果是这样的话,你可能是一个受害者,HFS +文件系统的坚持来存储"é"(U + 00e9)字符正常形式分解(NFD)模式,即为"E"+"́"(U + 0065 + 0301).
30 |
31 | `勒% %`实际上是正确的,`% %`在U+ UTF-8版本00e9预期由Web服务器. 问题是OS X转了. [u + 00e9]进入之内[0065+0301+],从而`勒% %`不再工作. 相反,只有`勒卡雷连铸% 81`结束`81 %`将匹配[0065+0301+]最后.
32 |
33 | 这是OS X独有的. 世界上其他地方没有这样做,当然也不是你最可能运行Linux的Web服务器. 这也不是雨果特有的问题. 其他人在他们的HTML文件中有重音字符时就被这个咬了.
34 |
35 | 注意,这个问题并不具体于拉丁语脚本. 日本的Mac用户经常遇到相同的问题,例如`だ`分解成`た`和`与# x3099;`. (读[日本perl用户文章][]).
36 |
37 | rsync 3. x的救援!从[服务器故障的答案][]:
38 |
39 | > 你可以使用rsync的`ℴℴiconv`选择UTF-8 NFC与NFD之间转换,至少如果你的Mac. 有一个特别的`utf-8-mac`字符集是UTF-8 NFD. 因此,为了将文件从Mac复制到Web服务器,您需要运行类似于:
40 | >
41 | > `rsync -ℴℴiconv = utf-8-mac,UTF-8 localdir / mywebserver: remotedir /`
42 | >
43 | > 这会将所有本地文件名由UTF-8 NFD为NFC在远程服务器. 文件的内容不会受到影响. ℴ[服务器故障][]
44 |
45 | 请确保你有rsync 3的最新版本. 装X. rsync,OS X的船只已经过时. 即使是包装版本10.10(优诗美地国家公园)是版本2.6.9协议版本29. 这个`ℴℴiconv`国旗是新的rsync 3. X.
46 |
47 | ### 论坛参考
48 |
49 | -
50 | - [http://wiki.apache.org/subversion/nonnormalizingunicodecompositionawareness](http://wiki.apache.org/subversion/NonNormalizingUnicodeCompositionAwareness)
51 | - [http: / /恩. 维基百科. org /维基/ unicode_equivalence #例子](https://en.wikipedia.org/wiki/Unicode_equivalence#Example)
52 | -
53 | -
54 |
55 | [an answer posted on server fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
56 |
57 | [japanese perl users article]: http://perl-users.jp/articles/advent-calendar/2010/english/24 "Encode::UTF8Mac makes you happy while handling file names on MacOSX"
58 |
59 | [server fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
60 |
--------------------------------------------------------------------------------
/translate-js/test/setObjectKey.test.js:
--------------------------------------------------------------------------------
1 | const { test } = require('ava')
2 | const fs = require('fs')
3 | const [tree, truetree ] = require('./setObjectKey.Object.js')
4 | const {setObjectKey, translateValue} = require('../src/setObjectKey.js')
5 | var newObject = (oldObject) =>JSON.parse(JSON.stringify(oldObject));
6 |
7 | test(' test baidu',async t =>{
8 | let newTree = await setObjectKey(newObject(tree), 'baidu')
9 | t.deepEqual(newTree, truetree)
10 | })
11 |
12 | test(' test youdao',async t =>{
13 | let newTree = await setObjectKey(newObject(tree), 'youdao')
14 | t.deepEqual(newTree, truetree)
15 | })
16 |
17 | test(' test google',async t =>{
18 | let newTree = await setObjectKey(newObject(tree), 'google')
19 | t.deepEqual(newTree, truetree)
20 | })
21 |
22 |
23 | test(' test translate no key == value ',async t =>{
24 | let noValue = await setObjectKey(newObject({type:'asdf'}), 'baidu')
25 | t.false(noValue)
26 | })
27 |
28 | test(' test translate code or html false',async t =>{
29 | let noValue = await setObjectKey(newObject({
30 | "type": "html",
31 | "value": ""
32 | }), 'baidu')
33 | t.false(noValue)
34 | })
35 |
36 | test(' test translateValue ',async t =>{
37 | let value = ['hello world','hello world']
38 | let result = await translateValue(value, 'baidu').then(x => x)
39 | t.deepEqual(result, [`你好世界`,`你好世界`])
40 | })
41 |
42 | // test.before('test only code AST ', t =>{
43 | // let obj = {
44 | // "type": "root",
45 | // "children": [
46 | // {
47 | // "type": "code",
48 | // "lang": "js",
49 | // "value": "var a = 'asdf'",
50 | // "position": {
51 | // "start": {
52 | // "line": 1,}}}
53 | // ]}
54 | // let tranArray = []
55 | // let sum = 0
56 | // sum = deep(obj, tranArray)
57 | // t.is(sum, 0)
58 | // })
59 |
60 | // test.before(" test deep func get values from obj", t =>{
61 | // let obj = {'id':1,children:{
62 | // id:2,
63 | // value: 'hello world'
64 | // },position:[{value:"hello"}]};
65 |
66 | // let tranArray = []
67 | // let sum = 0
68 | // sum = deep(obj,tranArray)
69 |
70 | // t.is(sum,2)
71 | // })
72 |
73 | // test.before(" test setdeep func set values from resultArray", t =>{
74 | // let obj = {'id':1,children:{
75 | // id:2,
76 | // value: 'hello world'
77 | // },position:[{value:"hello"}]};
78 | // let sum = 2
79 | // sum = setdeep(obj, ['你好世界', '你好'])
80 | // let newobj = {'id':1,children:{
81 | // id:2,
82 | // value: '你好世界'
83 | // },position:[{value:"你好"}]};
84 | // t.is(sum, 0)
85 | // t.deepEqual(obj,newobj)
86 | // })
--------------------------------------------------------------------------------
/translate-js/test/setObjectKey.Object.js:
--------------------------------------------------------------------------------
1 |
2 | const { test } = require('ava')
3 |
4 | const tree = {
5 | "type": "root",
6 | "children": [
7 | {
8 | "type": "heading",
9 | "depth": 2,
10 | "children": [
11 | {
12 | "type": "text",
13 | "value": "Hello",
14 | "position": {
15 | "start": {
16 | "line": 1,
17 | "column": 4,
18 | "value": "Hello",
19 | "offset": 3
20 | },
21 | "end": {
22 | "line": 1,
23 | "column": 9,
24 | "offset": 8
25 | },
26 | "indent": []
27 | }
28 | }
29 | ],
30 | "position": {
31 | "start": {
32 | "line": 1,
33 | "column": 1,
34 | "offset": 0
35 | },
36 | "end": {
37 | "line": 1,
38 | "column": 9,
39 | "offset": 8
40 | },
41 | "indent": [],
42 | "value": "world"
43 | }
44 | }
45 | ],
46 | "position": {
47 | "start": {
48 | "line": 1,
49 | "column": 1,
50 | "offset": 0
51 | },
52 | "end": {
53 | "line": 2,
54 | "column": 1,
55 | "offset": 9
56 | }
57 | }
58 | }
59 |
60 |
61 |
62 | const truetree = {
63 | "type": "root",
64 | "children": [
65 | {
66 | "type": "heading",
67 | "depth": 2,
68 | "children": [
69 | {
70 | "type": "text",
71 | "value": "你好",
72 | "position": {
73 | "start": {
74 | "line": 1,
75 | "column": 4,
76 | "value": "你好",
77 | "offset": 3
78 | },
79 | "end": {
80 | "line": 1,
81 | "column": 9,
82 | "offset": 8
83 | },
84 | "indent": []
85 | }
86 | }
87 | ],
88 | "position": {
89 | "start": {
90 | "line": 1,
91 | "column": 1,
92 | "offset": 0
93 | },
94 | "end": {
95 | "line": 1,
96 | "column": 9,
97 | "offset": 8
98 | },
99 | "indent": [],
100 | "value": "世界"
101 | }
102 | }
103 | ],
104 | "position": {
105 | "start": {
106 | "line": 1,
107 | "column": 1,
108 | "offset": 0
109 | },
110 | "end": {
111 | "line": 2,
112 | "column": 1,
113 | "offset": 9
114 | }
115 | }
116 | }
117 |
118 | module.exports = [tree, truetree]
--------------------------------------------------------------------------------
/translate-js/README.md:
--------------------------------------------------------------------------------
1 | # translate .md to *.md
2 |
3 | like
4 | ```
5 | .md to .zh.md
6 | ```
7 |
8 | [](https://travis-ci.org/chinanf-boy/translate-js)
9 | [](https://codecov.io/gh/chinanf-boy/translate-js)
10 | [](https://github.com/chinanf-boy/translate-js/blob/master/License)
11 | [](https://nodei.co/npm/translate-mds/)
12 |
13 | ## 这个项目是 hugo 官方文档
14 |
15 | ``` js
16 | npm install -g translate-mds
17 | ```
18 |
19 | ``` js
20 | // all folder
21 | translateMds md/
22 |
23 | //or single file
24 |
25 | translateMds test.md
26 | ```
27 | cli
28 | ``` js
29 | Usage
30 | $ translateMds [folder name] [options]
31 |
32 | Example
33 | $ translateMds md/
34 |
35 | [options]
36 | -a API : default < baidu > {google,baidu,youdao}
37 |
38 | -f from : default < en >
39 |
40 | -t to : default < zh >
41 |
42 | -N num : default < 5 > {async number}
43 |
44 | -D debug : default < false >
45 |
46 | -R rewrite : default < false > {yes/no retranslate and rewrite translate file}
47 |
48 | ```
49 | ---
50 |
51 | ## 项目引用
52 |
53 | ``` js
54 | const translate = require('translate-mds')
55 | //
56 | let results = await translate([__dirname+'/testWrite1.md'])
57 | //or
58 | let results = await translate([__dirname+'/md/'])
59 | // results is Array
60 |
61 |
62 | ```
63 |
64 | ## translate(options,debug)
65 |
66 | ## options 当用 []
67 |
68 | [ aFile,api,tF,tT ] = options
69 | ## options 当 用 {}
70 |
71 | - aFile
72 |
73 | > absolute file
74 |
75 | - api
76 |
77 | >``default : baidu``
78 |
79 | >{'google','baidu','youdao'}
80 |
81 | - tF
82 |
83 | >``default : en``
84 |
85 | - tT
86 |
87 | >``default : zh``
88 |
89 | - debug
90 |
91 | > ``default : verbose``
92 | # 下面的Demo 你 应该
93 |
94 | 下载这个项目
95 |
96 | ```
97 | git clone https://github.com/chinanf-boy/translate-js.git
98 | ```
99 |
100 | ## Demo
101 |
102 | [](https://asciinema.org/a/aPDJ0Vdt3awZs8NJV8DtYH0ww)
103 |
104 | # Video sometime very quick
105 |
106 | - So the cmd Step is
107 |
108 | ``` js
109 | node index.js md/
110 | ```
111 |
112 | > Done !! Or
113 |
114 | [查看我 you dont know js 翻译](https://github.com/chinanf-boy/You-Dont-Know-JS)
115 |
116 | 所有的 ``.zh.md`` 都是通过 下面命令
117 |
118 | ```
119 | tanslateMds
120 | ```
121 |
122 |
123 | > ⏰ tips 有时会抽风,正在查找 会卡住 Issue
124 |
125 | >你只要再运行。!!!
126 |
127 | # 抱歉 ,我能力不足,node 并发问题在于,我也不知道问题在哪里。
128 |
129 | # 问题:忽然间就没有网络流量的速度一样,不知道这是不是,禁止IP ????
130 |
131 | # 当 并数是 ``1`` 的时候,很凑巧的,You-dont-know-js 68个md文件,能成功几次,但是当并发数超 1,特别是临近结束的那几个文件,等待就一直在转,这时网络速度变0,这时就需要 ctrl + c ,终止了!
132 | # [ X ] 提高http之类的md格式准确率
133 | # [ X ] 自动换 翻译源
134 |
135 | # [ x ] 启用 md AST
136 |
137 | 使用 [``remark``](https://github.com/wooorm/remark) 提高精准度
138 |
139 | 使用 [``translate.js``](https://github.com/Selection-Translator/translation.js) 完成 与翻译网站的交互
140 |
141 | 还有个 [异步Promise 递归的 例子](https://github.com/chinanf-boy/translate-js/blob/master/src/setObjectKey.js#L78)
142 |
--------------------------------------------------------------------------------
/translate-js/md/1.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Accented Characters in URLs
3 | linktitle: Accented Characters in URLs
4 | description: If you're having trouble with special characters in your taxonomies or titles adding odd characters to your URLs.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | keywords: [urls,multilingual,special characters]
9 | categories: [troubleshooting]
10 | menu:
11 | docs:
12 | parent: "troubleshooting"
13 | weight:
14 | draft: false
15 | slug:
16 | aliases: [/troubleshooting/categories-with-accented-characters/]
17 | toc: true
18 | ---
19 |
20 | ## Trouble: Categories with accented characters
21 |
22 | > One of my categories is named "Le-carré," but the link ends up being generated like this:
23 | >
24 | > ```
25 | > categories/le-carr%C3%A9
26 | > ```
27 | >
28 | > And not working. Is there an easy fix for this that I'm overlooking?
29 |
30 | ## Solution
31 |
32 | Are you a macOS user? If so, you are likely a victim of HFS Plus file system's insistence to store the "é" (U+00E9) character in Normal Form Decomposed (NFD) mode, i.e. as "e" + " ́" (U+0065 U+0301).
33 |
34 | `le-carr%C3%A9` is actually correct, `%C3%A9` being the UTF-8 version of U+00E9 as expected by the web server. The problem is that OS X turns [U+00E9] into [U+0065 U+0301], and thus `le-carr%C3%A9` no longer works. Instead, only `le-carre%CC%81` ending with `e%CC%81` would match that [U+0065 U+0301] at the end.
35 |
36 | This is unique to OS X. The rest of the world does not do this, and most certainly not your web server which is most likely running Linux. This is not a Hugo-specific problem either. Other people have been bitten by this when they have accented characters in their HTML files.
37 |
38 | Note that this problem is not specific to Latin scripts. Japanese Mac users often run into the same issue; e.g., with `だ` decomposing into `た` and `゙`. (Read the [Japanese Perl users article][]).
39 |
40 | Rsync 3.x to the rescue! From [an answer posted on Server Fault][]:
41 |
42 | > You can use rsync's `--iconv` option to convert between UTF-8 NFC & NFD, at least if you're on a Mac. There is a special `utf-8-mac` character set that stands for UTF-8 NFD. So to copy files from your Mac to your web server, you'd need to run something like:
43 | >
44 | > `rsync -a --iconv=utf-8-mac,utf-8 localdir/ mywebserver:remotedir/`
45 | >
46 | > This will convert all the local filenames from UTF-8 NFD to UTF-8 NFC on the remote server. The files' contents won't be affected. - [Server Fault][]
47 |
48 | Please make sure you have the latest version of rsync 3.x installed. The rsync that ships with OS X is outdated. Even the version that comes packaged with 10.10 (Yosemite) is version 2.6.9 protocol version 29. The `--iconv` flag is new in rsync 3.x.
49 |
50 | ### Discussion Forum References
51 |
52 | * http://discourse.gohugo.io/t/categories-with-accented-characters/505
53 | * http://wiki.apache.org/subversion/NonNormalizingUnicodeCompositionAwareness
54 | * https://en.wikipedia.org/wiki/Unicode_equivalence#Example
55 | * http://zaiste.net/2012/07/brand_new_rsync_for_osx/
56 | * https://gogo244.wordpress.com/2014/09/17/drived-me-crazy-convert-utf-8-mac-to-utf-8/
57 |
58 | [an Answer posted on Server Fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
59 | [Japanese Perl users article]: http://perl-users.jp/articles/advent-calendar/2010/english/24 "Encode::UTF8Mac makes you happy while handling file names on MacOSX"
60 | [Server Fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
61 |
--------------------------------------------------------------------------------
/translate-js/md/about/aboutme/me.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Accented Characters in URLs
3 | linktitle: Accented Characters in URLs
4 | description: If you're having trouble with special characters in your taxonomies or titles adding odd characters to your URLs.
5 | date: 2017-02-01
6 | publishdate: 2017-02-01
7 | lastmod: 2017-02-01
8 | keywords: [urls,multilingual,special characters]
9 | categories: [troubleshooting]
10 | menu:
11 | docs:
12 | parent: "troubleshooting"
13 | weight:
14 | draft: false
15 | slug:
16 | aliases: [/troubleshooting/categories-with-accented-characters/]
17 | toc: true
18 | ---
19 |
20 | ## Trouble: Categories with accented characters
21 |
22 | > One of my categories is named "Le-carré," but the link ends up being generated like this:
23 | >
24 | > ```
25 | > categories/le-carr%C3%A9
26 | > ```
27 | >
28 | > And not working. Is there an easy fix for this that I'm overlooking?
29 |
30 | ## Solution
31 |
32 | Are you a macOS user? If so, you are likely a victim of HFS Plus file system's insistence to store the "é" (U+00E9) character in Normal Form Decomposed (NFD) mode, i.e. as "e" + " ́" (U+0065 U+0301).
33 |
34 | `le-carr%C3%A9` is actually correct, `%C3%A9` being the UTF-8 version of U+00E9 as expected by the web server. The problem is that OS X turns [U+00E9] into [U+0065 U+0301], and thus `le-carr%C3%A9` no longer works. Instead, only `le-carre%CC%81` ending with `e%CC%81` would match that [U+0065 U+0301] at the end.
35 |
36 | This is unique to OS X. The rest of the world does not do this, and most certainly not your web server which is most likely running Linux. This is not a Hugo-specific problem either. Other people have been bitten by this when they have accented characters in their HTML files.
37 |
38 | Note that this problem is not specific to Latin scripts. Japanese Mac users often run into the same issue; e.g., with `だ` decomposing into `た` and `゙`. (Read the [Japanese Perl users article][]).
39 |
40 | Rsync 3.x to the rescue! From [an answer posted on Server Fault][]:
41 |
42 | > You can use rsync's `--iconv` option to convert between UTF-8 NFC & NFD, at least if you're on a Mac. There is a special `utf-8-mac` character set that stands for UTF-8 NFD. So to copy files from your Mac to your web server, you'd need to run something like:
43 | >
44 | > `rsync -a --iconv=utf-8-mac,utf-8 localdir/ mywebserver:remotedir/`
45 | >
46 | > This will convert all the local filenames from UTF-8 NFD to UTF-8 NFC on the remote server. The files' contents won't be affected. - [Server Fault][]
47 |
48 | Please make sure you have the latest version of rsync 3.x installed. The rsync that ships with OS X is outdated. Even the version that comes packaged with 10.10 (Yosemite) is version 2.6.9 protocol version 29. The `--iconv` flag is new in rsync 3.x.
49 |
50 | ### Discussion Forum References
51 |
52 | * http://discourse.gohugo.io/t/categories-with-accented-characters/505
53 | * http://wiki.apache.org/subversion/NonNormalizingUnicodeCompositionAwareness
54 | * https://en.wikipedia.org/wiki/Unicode_equivalence#Example
55 | * http://zaiste.net/2012/07/brand_new_rsync_for_osx/
56 | * https://gogo244.wordpress.com/2014/09/17/drived-me-crazy-convert-utf-8-mac-to-utf-8/
57 |
58 | [an Answer posted on Server Fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
59 | [Japanese Perl users article]: http://perl-users.jp/articles/advent-calendar/2010/english/24 "Encode::UTF8Mac makes you happy while handling file names on MacOSX"
60 | [Server Fault]: http://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd "Converting UTF-8 NFD filenames to UTF-8 NFC in either rsync or afpd, Server Fault Discussion"
61 |
--------------------------------------------------------------------------------
/translate-js/bin/translateExports.js:
--------------------------------------------------------------------------------
1 | 'use script'
2 | const fs = require('mz/fs')
3 | const path = require('path')
4 | const tjs = require('translation.js')
5 | const {Listmd} = require('../src/readmd.js')
6 | const meow = require('meow');
7 | const chalk = require('chalk');
8 | const cutMdhead = require('../src/cutMdhead.js')
9 | const remark = require('remark')
10 | const { logger } = require('../config/loggerConfig.js') // winston config
11 | let defaultJson = '../config/defaultConfig.json' // default config---
12 | let defaultConfig = require(defaultJson) //---
13 | let jsonFile = path.resolve(__dirname, '../config.json')
14 | const writeJson = require('../util/writeJson.js')
15 | //
16 | let done = 0
17 | const { setDefault, debugTodo, fromTodo, toTodo, apiTodo } = require('../src/optionsTodo.js')
18 | // Main Function
19 | function O2A(options){
20 | let {aFile, api, tF, tT} = options
21 | return [aFile, api, tF, tT]
22 | }
23 |
24 | /**
25 | * @description translateMds main
26 | * @param {Array|Object} options
27 | * @param {Boolean|String} debug
28 | * @returns {Array}
29 | */
30 | async function translateMds(options,debug){
31 |
32 | let absoluteFile, api, tranFrom, tranTo
33 | if(!options) throw logger.error('options is NULL')
34 |
35 | // options is Array or Object
36 | if(options instanceof Array){
37 | [absoluteFile, api, tranFrom, tranTo] = options
38 | }else if(options instanceof Object){
39 | [absoluteFile, api, tranFrom, tranTo] = O2A(options)
40 | }
41 | // file is absolute
42 | if(!absoluteFile || !path.isAbsolute(absoluteFile)){
43 | throw logger.error('translateMds absoluteFile is no absolute ')
44 | }
45 | // change defaultConfig from options
46 | // return first option
47 | debug = setDefault(debug, debugTodo, defaultConfig)
48 | logger.level = debug
49 | tranFrom = setDefault(tranFrom, fromTodo, defaultConfig)
50 | tranTo = setDefault(tranTo, toTodo, defaultConfig)
51 | api = setDefault(api, apiTodo, defaultConfig)
52 |
53 | // rewrite config.json
54 | // Error: this json error here , see test "async translate"
55 | await writeJson(jsonFile, defaultConfig)
56 |
57 | // and then, setObjectKey.js can require the new config.json
58 | const {setObjectKey} = require('../src/setObjectKey.js')
59 | // const { writeDataToFile } = require('../src/writeDataToFile.js')
60 |
61 | async function t(data){
62 |
63 | let head,mdAst,translateMdAst
64 | [body, head] = cutMdhead(data)
65 | // to AST
66 | // try{
67 | mdAst = remark.parse(body)
68 | // }catch(x){
69 | // console.log('remark parse error')
70 | // throw x
71 | // }
72 | // try{
73 | // translate AST value
74 | translateMdAst = await setObjectKey(mdAst, api)
75 | // }catch(x){
76 | // console.log(' translate error')
77 | // throw x
78 | // }
79 | // try{
80 | if(translateMdAst){
81 | // Ast to markdown
82 | body = remark.stringify(translateMdAst)
83 | return head+'\n'+body
84 | }
85 | // }catch(x){
86 | // console.log(chalk.red('remark stringify error'))
87 | // throw x
88 | // }
89 | // console.log('t','-----------t')
90 | return translateMdAst
91 | }
92 | //
93 | let results = []
94 |
95 | logger.verbose(chalk.blue('Starting 翻译')+chalk.red(absoluteFile));
96 | // get floder markdown files Array
97 | const getList = await Listmd(absoluteFile)
98 |
99 | for (i in getList){
100 | let value = getList[i]
101 | // 去掉 .**.zh 的后缀 和 自己本身 .match(/\.[a-zA-Z]+\.md+/)
102 | if(value.endsWith(`.${tranTo}.md`) || value.match(/\.[a-zA-Z]+\.md+/) || !value.endsWith('.md'))continue
103 | let readfile = await fs.readFile(value, 'utf8')
104 | let _translate = await t(readfile).then(x =>x).catch(x => {
105 | console.log(x)
106 | return false
107 | })
108 |
109 | // logger.info(_translate)
110 | if(_translate){
111 | results.push(_translate)
112 | }else{
113 | results.push('')
114 | }
115 | // console.trace(chalk.red('look me'))
116 |
117 | }
118 | // logger.error(++done,'---------------------')
119 | return results
120 | }
121 |
122 |
123 | module.exports = translateMds
--------------------------------------------------------------------------------
/translate-js/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "translate-mds",
3 | "version": "2.5.6",
4 | "lockfileVersion": 1,
5 | "dependencies": {
6 | "ansi-regex": {
7 | "version": "2.1.1",
8 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
9 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
10 | },
11 | "ansi-styles": {
12 | "version": "2.2.1",
13 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
14 | "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
15 | },
16 | "any-promise": {
17 | "version": "1.3.0",
18 | "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
19 | "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
20 | },
21 | "blueimp-md5": {
22 | "version": "2.10.0",
23 | "resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.10.0.tgz",
24 | "integrity": "sha512-EkNUOi7tpV68TqjpiUz9D9NcT8um2+qtgntmMbi5UKssVX2m/2PLqotcric0RE63pB3HPN/fjf3cKHN2ufGSUQ=="
25 | },
26 | "cli-cursor": {
27 | "version": "2.1.0",
28 | "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz",
29 | "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU="
30 | },
31 | "cli-spinners": {
32 | "version": "1.1.0",
33 | "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-1.1.0.tgz",
34 | "integrity": "sha1-8YR7FohE2RemceudFH499JfJDQY="
35 | },
36 | "escape-string-regexp": {
37 | "version": "1.0.5",
38 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
39 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
40 | },
41 | "has-ansi": {
42 | "version": "2.0.0",
43 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
44 | "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE="
45 | },
46 | "log-symbols": {
47 | "version": "1.0.2",
48 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-1.0.2.tgz",
49 | "integrity": "sha1-N2/3tY6jCGoPCfrMdGF+ylAeGhg=",
50 | "dependencies": {
51 | "chalk": {
52 | "version": "1.1.3",
53 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
54 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg="
55 | }
56 | }
57 | },
58 | "mimic-fn": {
59 | "version": "1.1.0",
60 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.1.0.tgz",
61 | "integrity": "sha1-5md4PZLonb00KBi1IwudYqZyrRg="
62 | },
63 | "mz": {
64 | "version": "2.7.0",
65 | "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
66 | "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q=="
67 | },
68 | "object-assign": {
69 | "version": "4.1.1",
70 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
71 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
72 | },
73 | "onetime": {
74 | "version": "2.0.1",
75 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz",
76 | "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ="
77 | },
78 | "ora": {
79 | "version": "1.3.0",
80 | "resolved": "https://registry.npmjs.org/ora/-/ora-1.3.0.tgz",
81 | "integrity": "sha1-gAeN0rkqk0r2ajrXKluRBpTt5Ro=",
82 | "dependencies": {
83 | "chalk": {
84 | "version": "1.1.3",
85 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
86 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg="
87 | }
88 | }
89 | },
90 | "restore-cursor": {
91 | "version": "2.0.0",
92 | "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz",
93 | "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368="
94 | },
95 | "signal-exit": {
96 | "version": "3.0.2",
97 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
98 | "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
99 | },
100 | "strip-ansi": {
101 | "version": "3.0.1",
102 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
103 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8="
104 | },
105 | "supports-color": {
106 | "version": "2.0.0",
107 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
108 | "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc="
109 | },
110 | "thenify": {
111 | "version": "3.3.0",
112 | "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz",
113 | "integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk="
114 | },
115 | "thenify-all": {
116 | "version": "1.6.0",
117 | "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
118 | "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY="
119 | },
120 | "translation.js": {
121 | "version": "0.6.4",
122 | "resolved": "https://registry.npmjs.org/translation.js/-/translation.js-0.6.4.tgz",
123 | "integrity": "sha512-ZayitbGTEf/k/LkmdHWfzy1wqTH0O8ZK75+eKLlaUkTzIZmeRPLOYfvAUy2KctrIAt/v4HT5eGt7JxaMfSgY5g=="
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/translate-js/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | ( async function(){
3 | 'use script'
4 | process.on('uncaughtException', function(err){
5 | console.error('got an error: %s', err);
6 | process.exit(1);
7 | });
8 | const async = require('async')
9 |
10 | const fs = require('fs')
11 | const asyncfs = require('mz/fs')
12 | const path = require('path')
13 | // const tjs = require('translation.js')
14 | const {Listmd} = require('./src/readmd.js')
15 | const meow = require('meow');
16 | const ora = require('ora')
17 | const chalk = require('chalk');
18 | // const cutMdhead = require('./src/cutMdhead.js')
19 | const remark = require('remark')
20 | // option todo list
21 | const { setDefault, debugTodo, fromTodo, toTodo, apiTodo, rewriteTodo, numTodo } = require('./src/optionsTodo.js')
22 |
23 | // config
24 | const { logger } = require('./config/loggerConfig.js') // winston config
25 | let defaultJson = './config/defaultConfig.json' // default config---
26 | let defaultConfig = require(defaultJson) //---
27 | let configJson = path.resolve(__dirname, 'config.json')
28 | // write config.json
29 | const writeJson = require('./util/writeJson.js')
30 | // next ready auto select api source
31 | // cli cmd
32 | const cli = meow(`
33 | Usage
34 | $ translateMds [folder name] [options]
35 |
36 | Example
37 | $ translateMds md/
38 |
39 | [options]
40 | -a API : default < baidu > {google,baidu,youdao}
41 |
42 | -f from : default < en >
43 |
44 | -t to : default < zh >
45 |
46 | -N num : default < 5 > {async number}
47 |
48 | -D debug
49 |
50 | -R rewrite : default < false > {yes/no retranslate and rewrite translate file}
51 |
52 | -T timeout : default {this 功能 待续}
53 | `);
54 |
55 | const APIs = ['google','baidu','youdao']
56 | // Fix write file Path is absoulte
57 | var dir = cli.input[0]
58 | if(!dir){
59 | return console.log(chalk.green("--> V"+cli.pkg.version,cli.help))
60 | }
61 | // change defaultConfig from cli
62 | // if true return first option
63 | // else return
64 | let debug = setDefault(cli.flags['D'], debugTodo, defaultConfig)
65 | logger.level = debug
66 | let tranFr = setDefault(cli.flags['f'], fromTodo, defaultConfig)
67 | let tranTo = setDefault(cli.flags['t'], toTodo, defaultConfig)
68 | let api = setDefault(cli.flags['a'], apiTodo, defaultConfig)
69 | let rewrite = setDefault(cli.flags['R'], rewriteTodo, defaultConfig)
70 | let asyncNum = setDefault(cli.flags['N'], numTodo, defaultConfig)
71 | // let Time = setDefault(cli.flags['T'], timeoutTodo, defaultConfig)
72 |
73 | // Now rewrite config.json
74 | await writeJson(configJson, defaultConfig) // 用 defaultConfig 写入 config.json
75 | const translateMds = require('./bin/translateExports.js')
76 |
77 | // and then, setObjectKey.js can require the new config.json
78 | // const {setObjectKey} = require('./src/setObjectKey.js')
79 | const { writeDataToFile, insert_flg } = require('./src/writeDataToFile.js')
80 | //ready
81 | logger.info(chalk.blue('Starting 翻译')+chalk.red(dir));
82 |
83 | // main func
84 |
85 | // get floder markdown files Array
86 | const getList = await Listmd(path.resolve(process.cwd(),dir))
87 |
88 | logger.info(chalk.blue(`总文件数 ${getList.length}, 有些文件会跳过`));
89 |
90 | let Done = 0
91 | let noDone = []
92 | function doneShow(str) {
93 | const s = ora(str).start()
94 | s.color = 'red'
95 | s.succeed()
96 | }
97 | let showAsyncnum = 0
98 | async.mapLimit(getList, asyncNum, runTranslate,
99 | (err, IsTranslateS) =>{
100 | if(err)throw err
101 | Done++
102 | if(IsTranslateS.every(x =>!!x)){
103 | doneShow(`All Done`)
104 | }else{
105 | doneShow(`Some No Done`)
106 | }
107 | // console.log('map Limit outting')
108 | }
109 | )
110 |
111 | /**
112 | * @description async Translate filename value , Return true or false
113 | * @param {String} value
114 | * @returns {Boolean}
115 | */
116 |
117 | async function runTranslate(value){
118 | Done++
119 |
120 | let localDone = Done
121 | if(value.endsWith(`.${tranTo}.md`) || value.match(/\.[a-zA-Z]+\.md+/) || !value.endsWith('.md')) {
122 | logger.debug(chalk.blue(`翻译的 或者 不是 md 文件的 有 ${localDone}`));
123 | return true
124 | }
125 | if(!rewrite && fs.existsSync( insert_flg(value,`.${tranTo}`, 3 ))){
126 | logger.debug(chalk.blue(`已翻译, 不覆盖 ${localDone}`));
127 | return true
128 | }
129 | // throw new Error('why')
130 | showAsyncnum++
131 | let start = new Date().getTime();
132 | //
133 | const spinner = ora(`${process.pid} Loading translate .. ${path.basename(value)} `)
134 | spinner.color = 'yellow'
135 | spinner.start();
136 | let _translateMds = await translateMds([value, api, tranFr, tranTo],debug).then(data =>{
137 | let endtime = new Date().getTime() - start;
138 | //
139 |
140 | spinner.text +='get data'
141 | if(data.every(x =>x!='')){
142 | writeDataToFile(data, value)
143 | spinner.text = `已搞定 第 ${localDone} 文件 - 并发${chalk.blue(showAsyncnum)} -- ${chalk.blue(endtime+'md')} - ${path.basename(value)} `
144 | spinner.succeed()
145 | showAsyncnum--
146 | return true
147 | }
148 | spinner.text = `没完成 第 ${localDone} 文件 - 并发${chalk.blue(showAsyncnum)} -- ${chalk.blue(endtime+'md')} - ${value} `
149 | spinner.fail()
150 |
151 | showAsyncnum--
152 | // if(asyscNum)
153 | // throw new Error(`translate ${value} fail`)
154 | return false
155 |
156 | }).catch(x =>{
157 | console.log('bad ass $$$$$$$$$')
158 | throw x
159 | })
160 | return _translateMds
161 | //read each file
162 | }
163 |
164 | function timeout(ms) {
165 | return new Promise((resolve, reject) => {
166 | setTimeout(resolve, ms);
167 | });
168 | }
169 |
170 | while(Done){
171 | const time = 1000
172 | await timeout(time) //translate will change Done num
173 | // if time ms , the Done num is no change
174 | // may the project if freeze, this is Bug
175 | // bug i dont know , Bug from where
176 | // seem like when project running and the network no download speed
177 | // just like Frozen
178 | // keep
179 | // const spinner = ora(`Loading translate .. ${path.basename(value)} `)
180 | // that running
181 |
182 |
183 | if(Done > getList.length){
184 | // console.log(Done)
185 | break
186 | }
187 | }
188 | // console.log('while outting')
189 |
190 | // if(Done == getList.length){
191 | // throw new Error(`${time} ok`)
192 |
193 |
194 | // }
195 | // if(Done == timeoutDone){
196 | // console.log('/###################',process.pid)
197 | // console.log(':))))))))))')
198 | // throw new Error(`${time} timeout`)
199 | // console.log('/###################',process.pid)
200 | // }
201 | // }
202 |
203 | // logger.info(getList)
204 | // false
205 | // 因为 getList.map
206 | // 困不住 await
207 | // 用 for 才行
208 | // ../bin/translateExports.js #44
209 | })()
210 |
--------------------------------------------------------------------------------
/translate-js/src/setObjectKey.js:
--------------------------------------------------------------------------------
1 | const tjs = require('translation.js')
2 | const chalk = require('chalk')
3 | const {logger} = require('../config/loggerConfig.js')
4 | // get config.json
5 | const configs = require('../config.json')
6 | let tranF, tranT
7 | tranF = configs['from']
8 | tranT = configs['to']
9 | logger.level = configs.logger.level
10 |
11 | // get translate result
12 |
13 | /**
14 | * @description
15 | * @param {String} value
16 | * @param {String} api
17 | * @returns {String}
18 | */
19 | async function translateValue(value, api){
20 | let thisTranString
21 | if(value instanceof Array){
22 | thisTranString = value.join('\n')
23 | }else{
24 | // console.log('value is string')
25 | }
26 | if(api == 'youdao' && tranT === 'zh'){
27 | tranT = tranT + '-CN'
28 | }
29 | // logger.log('debug',thisTranString,value,'----- first')
30 | return tjs.translate({
31 | text: thisTranString,
32 | api: api,
33 | from: tranF,
34 | to: tranT
35 | }).then(result => {
36 | if(!result.result){
37 | return ''
38 | }
39 | if(value.length == result.result.length){
40 | return result.result
41 | }
42 | // result.result.length,value.length
43 | logger.debug(chalk.yellow(`获得 ${api} 数据了~`));
44 | // get zh and -> write down same folder { me.md => me.zh.md }
45 | for (i in result.result){
46 | if(!value[i]){
47 | logger.log('debug','----------')
48 | }
49 | logger.log('debug','set- '+ chalk.green(value[i]) + ' to-> '+ chalk.yellow(result.result[i]))
50 | }
51 |
52 | // logger.log('error',value.length)
53 | if(value.length > result.result.length){
54 | return translateValue(value.slice(result.result.length),api).then(youdao =>{
55 | // tjs translate youdao BUG and tjs baidu will return undefined
56 | if(youdao){
57 | if(youdao instanceof Array){
58 | youdao.forEach(x => result.result.push(x))
59 | }else{
60 | result.result.push(youdao)
61 | }
62 | }
63 | logger.log('debug',JSON.stringify(result.result,null,2),chalk.cyan('集合 --------中 '))
64 | return result.result
65 |
66 | }).catch(x => logger.error(`${youdao}炸了`,x))
67 | // Promise.reject("bad youdao fanyi no get \\n")
68 |
69 | }
70 |
71 | // Bug translate.js return result.result Array
72 | if(value.length != result.result.length){
73 | // when \n in text medium,return 2 size Array
74 | return result.result
75 | }
76 |
77 |
78 | }).catch(error => {
79 | if(!error.code){
80 | logger.error(api,chalk.red( error,'出现程序错误'))
81 | }else{
82 | logger.debug(api,chalk.red( error.code,'出现了啦,不给数据'))
83 | }
84 | return ""
85 |
86 | })
87 |
88 | }
89 |
90 | /**
91 | * @description translate AST Key == value, return new Object
92 | * @param {Object} obj - AST
93 | * @param {String} api - defuault api
94 | * @returns {Object} - newObject
95 | */
96 | async function setObjectKey(obj, api) {
97 |
98 | let allAPi = ['baidu','google','youdao']
99 | let tranArray = []
100 | let thisTranArray = []
101 | let resultArray = []
102 | let newObj = JSON.parse(JSON.stringify(obj))
103 | let sum = 0 // single values
104 | /**
105 | * @description Find ``obj['type'] === 'value'`` ,and``tranArray.push(obj[key])``
106 | * @param {Object} obj
107 | * @param {String[]} tranArray
108 | * @returns {number} - find value number
109 | */
110 | function deep(obj, tranArray) {
111 | Object.keys(obj).forEach(function(key) {
112 |
113 | // no translate code content
114 | if(obj['type'] && ( obj['type'] === 'html' || obj['type'] === 'code')){
115 | return sum
116 | }
117 | (obj[key] && typeof obj[key] === 'object') && deep(obj[key], tranArray)
118 |
119 |
120 | if(key === 'value' && obj[key].trim()){
121 | tranArray.push(obj[key])
122 | sum++
123 | }
124 | });
125 | return sum
126 | };
127 |
128 | /**
129 | * @description Find ``obj['type'] === 'value'``, and use ``tranArrayZh.shift`` set ``obj['value']``
130 | * @param {any} obj - AST
131 | * @param {String[]} tranArrayZh
132 | * @returns
133 | */
134 | function setdeep(obj, tranArrayZh) {
135 | Object.keys(obj).forEach(function(key) {
136 |
137 | if(obj['type'] && ( obj['type'] === 'html' || obj['type'] === 'code')){
138 | return sum
139 | }
140 |
141 | (obj[key] && typeof obj[key] === 'object') && setdeep(obj[key], tranArrayZh)
142 |
143 | if(key === 'value' && obj[key].trim()){
144 | if(tranArrayZh.length){
145 | obj[key] = tranArrayZh.shift()
146 | sum--
147 | }
148 | }
149 | });
150 | return sum
151 | };
152 |
153 | // put obj values to tranArray
154 | if(!deep(obj, tranArray)){
155 | logger.error('no value', sum)
156 | return false
157 | }
158 | if(tranArray.length){
159 | thisTranArray = tranArray
160 | tranArray = []
161 | }
162 | // translate tranArray to zh
163 | // logger.log(tranArray)
164 | allAPi = allAPi.filter(x => x!=api)
165 | allAPi.push(api)
166 | for(let i in allAPi){
167 | logger.log('debug',chalk.yellow('使用',api))
168 | resultArray = await translateValue(thisTranArray, api)
169 | api = allAPi[i]
170 | if(resultArray && resultArray.length>=thisTranArray.length){
171 | break
172 | }
173 | }
174 |
175 | //BUG------
176 | // while(thisTranArray && (resultArray.length=0 && api){
177 | // logger.log('debug',chalk.yellow('使用',api))
178 | // resultArray = await translateValue(thisTranArray, api)
179 | // api = allAPi.shift()
180 | // }
181 | if(!resultArray ||(resultArray.length>'),chalk.green(resultArray))
193 | setdeep(newObj, resultArray)
194 | // if(sum != 0)console.log(sum,'sum')
195 |
196 | return newObj
197 | }
198 |
199 | module.exports = { setObjectKey, translateValue }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # translateMds
2 |
3 | [](https://github.com/chinanf-boy/Source-Explain)
4 |
5 | 版本``2.5.6``
6 |
7 | ## 简述
8 |
9 | 为了快速翻译`md`文章, 构建了这个翻译工具.
10 |
11 | [english](./README.en.zh)
12 |
13 | ## 为了做到这点, 有几个必要条件
14 |
15 | - 一 :翻译源API国内,我选择了[translate.js](https://github.com/Selection-Translator/translation.js)
16 |
17 | - 二 :提高md翻译的精准度。``「 翻译源可不管你是不是网址链接 」``,总会出现乱码,使用语法树,我选择[remark](https://github.com/Selection-Translator/translation.js)
18 |
19 | - 三 :符号问题。乱码情况,可不单单网址之类,中英文符号的替换,也是正确显示的关键。
20 |
21 | - 第四点,::这个项目版本没有完成的❌,当 ``一`` 翻译API 不给数据,似乎并不会报错,所以一直转圈圈。;P.
22 |
23 | 这里也是希望有人能 ``ISSUE 或 PULL `` 下下。
24 |
25 | ---
26 |
27 | ## 目录
28 |
29 | - [翻译API](#翻译源)
30 |
31 | - [remark-AST转换器](#remark)
32 |
33 | - [符号](#符号)
34 |
35 | - [什么都不要管冲冲冲-并发](#并发)
36 |
37 | - [其他](#其他)
38 |
39 | ---
40 | 开始吧。
41 |
42 | ## 翻译源
43 |
44 | 一开始,构建这个项目的中心,当然是围绕``翻译 API``
45 |
46 | 因为使用了 ``async/await`` 的特性, 这个API还提供语音
47 |
48 | [try_tjs.js](./try/try_tjs.js)
49 |
50 | ``` js
51 | (async function(){
52 | const tjs = require('translation.js')
53 |
54 | let thisTranString = "hello world"
55 | let api = "baidu"
56 | let tranF = "en"
57 | let tranT = "zh"
58 | let result = await tjs.translate({
59 | text: thisTranString,
60 | api: api,
61 | from: tranF,
62 | to: tranT
63 | })
64 | console.log(result.result)
65 | }
66 | )()
67 | ```
68 |
69 | ``result.result`` 是翻译结果 ``Array``类型,以 ``text`` 中 ``'\n'`` 换行符作为数组分隔的标准
70 |
71 | 示例
72 | ```
73 | npm run try:tjs
74 | ```
75 |
76 | > ⚠️,有几个点要注意。
77 |
78 | - ``text`` 过长 时,它不一定,会给全结果,这个时候就需要比较长度
79 |
80 | [./translate-js/src/setObjectKey.js#L53](./translate-js/src/setObjectKey.js#L53)
81 |
82 | ``` js
83 | if(value.length > result.result.length){
84 | // 递归异步翻译
85 | }
86 | ```
87 |
88 | - youdao 中文是 ``zh-CN``
89 |
90 | [./translate-js/src/setObjectKey.js#L26](./translate-js/src/setObjectKey.js#L26)
91 | ``` js
92 | if(api == 'youdao' && tranT === 'zh'){
93 | tranT = tranT + '-CN'
94 | }
95 | ```
96 |
97 | - 就因为,结果`result.result` 以 ``text`` 中 ``'\n'`` 分隔
98 |
99 | 确保没有``'\n'``,这个版本这个BUg, 还没有修复
100 |
101 | ``` js
102 | tranArray = tranArray.map(x=>{
103 | if(x.indexOf('\n')>=0){
104 | return x.replace(/[\n]/g,'')
105 | }
106 | return x
107 | })
108 | //, 去除每行中的 '\n'
109 | // 对于 md 的编译器转 HTML 来说,普遍 双换行符,才是换行。
110 | // 单换行忽视。
111 | ```
112 |
113 | - ``tjs ``获取数据错误, 做错误处理, ❌
114 |
115 | [./translate-js/src/setObjectKey.js#L78](./translate-js/src/setObjectKey.js#L78)
116 | ``` js
117 | .catch(error => {
118 | if(!error.code){
119 | logger.error(api,chalk.red( error,'出现程序错误'))
120 | }else{
121 | logger.debug(api,chalk.red( error.code,'出现了啦,不给数据'))
122 | }
123 | return ""
124 |
125 | })
126 | ```
127 |
128 | > 当卡住,不给数据情况,上面的错误并没有触发,想不懂。
129 |
130 | [⬆️目录,目录是谁,我怎么知道
](#目录)
131 |
132 | ## remark
133 |
134 | remark 清晰的 AST 语法树,我选择
135 |
136 | [语法树在线玩网站](http://astexplorer.net/#/Z1exs6BWMq)
137 |
138 | ``` md
139 | # Hello
140 | ```
141 |
142 | 语法树过于详细,显得过长,简要就是一个对象
143 |
144 | ``` js
145 | {
146 | "type": ***, //类型
147 | "children" : ***, //孩子 孩子有分不同的类型
148 | "position" : *** // 位置
149 | }
150 | ```
151 |
152 | [try/try_remark.js](try/try_remark.js)
153 | ``` js
154 | var remark = require('remark');
155 |
156 | var body = `# Hello`
157 |
158 | var mdAst = remark.parse(body)
159 |
160 | console.log('语法树 var mdAst = remark.parse(body) *****\n\n mdAst=',mdAst)
161 |
162 | var reBody = remark.stringify(mdAst)
163 |
164 | console.log('\n\n变回来 var reBody = remark.stringify(mdAst) ****\n\n reBody=',reBody)
165 |
166 | ```
167 |
168 | ``` bash
169 | npm run try:remark
170 | ```
171 |
172 | [⬆️目录,目录是谁,我怎么知道
](#目录)
173 |
174 | ---
175 |
176 | ## 符号
177 |
178 | [fixEntoZh.js](./translate-js/src/fixEntoZh.js)
179 |
180 | ``` js
181 | /**
182 | * @description
183 | * @param {Array|String} data
184 | * @returns {Array|String}
185 | */
186 | const fixEntoZh = function fixEntoZh(data){
187 | if(!(data instanceof Array)){
188 | data = data.trim()
189 | return halfStr(data)
190 | }else{
191 |
192 | data = data.map(x =>{
193 | return halfStr(x)
194 | })
195 |
196 | return data
197 | }
198 | }
199 | ```
200 |
201 | 当获得 ``data`` 后,类型分两种
202 |
203 | - String
204 |
205 | > 去两边空格,给 ``halfStr`` 完成下一步
206 |
207 | - Array
208 |
209 | > 遍历,然后每个都运行一边,结果返回替换原数组
210 |
211 | ### ``halfStr`` 函数
212 |
213 | 从名字上来看,半 字符串
214 |
215 | 其实是``二分法``,接受 ``String`` 类型
216 |
217 | ``` js
218 | const halfStr = (str) =>{
219 | if (str.length <= 1 ) {
220 | if(reg.test(str) || reg2(str)){ // 是否有中文符号
221 | return charZh2En(str) // 有,修复
222 | }
223 | return str // 没有,直接返回
224 | }
225 |
226 | let qian = str.substring(0, str.length/2) // 上部分
227 | let hou = str.substring(str.length/2, str.length) // 下部分
228 |
229 | return halfStr(qian) + halfStr(hou) // 返回结果
230 | }
231 | ```
232 |
233 | ### 验证 ``reg reg2``
234 |
235 | ``` js
236 | // 验证 1
237 | const reg = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
238 |
239 | // 验证 2
240 | const reg2 = (str) => {
241 | for(i in str){
242 | if( "~`!@#$^%&*()_+|-={}[]:";<>?,./\'".indexOf(str[i])>=0 ){
243 | return true
244 | }
245 | }
246 | return false
247 | }
248 | ```
249 |
250 | ### ``charZh2En``
251 |
252 | 这里我就分了两个等级,自定义转型,和普遍转型
253 |
254 | ``` js
255 | const Store = {
256 | // 第一优先级
257 | '“': '"',
258 | "‘": "'",
259 | ":": ": ",
260 | "/ ": "/",
261 | "ℴ": "-",
262 | "”": '"',
263 | "。": ". "
264 |
265 | }
266 | function charZh2En(str) {
267 | var tmp = '';
268 | for (var i = 0; i < str.length; i++) {
269 | if( Object.keys(Store).some(x =>x==str[i])){
270 | // 可以自己修正
271 | // 第一优先级
272 | tmp += Store[str[i]]
273 | }else{
274 | // 下面符号数值的转换,适合大多数情况,但第一优先级就是给那些例外的
275 | // 第二优先级
276 | tmp += String.fromCharCode(str.charCodeAt(i) - 65248)
277 | }
278 | }
279 | return tmp // 结果
280 | }
281 | ```
282 |
283 | [⬆️目录,目录是谁,我怎么知道
](#目录)
284 |
285 | ---
286 |
287 | ## 并发
288 |
289 | 借用 [``Async`` <-- 网址]((https://github.com/caolan/async)) 的力量
290 |
291 | 只有命令行有并发,``export`` 没有
292 |
293 | [./translate-js/index.js](./translate-js/index.js#L98)
294 | ``` js
295 | const async = require('async')
296 | async.mapLimit(getList, asyncNum, runTranslate,(err.result)=>{
297 | //do something
298 | }
299 | // getList 列表
300 | // asyncNum 并发数
301 | // runTranslate 异步函数 就是 开头定义 async function
302 | // (err,result) 结果函数
303 | ```
304 |
305 | 另外你可以看看 [async 使用的例子](https://github.com/alsotang/async_demo)
306 |
307 | [⬆️目录,目录是谁,我怎么知道
](#目录)
308 |
309 | ---
310 |
311 | ## 其他
312 |
313 | ### 命令行解析使用 [https://github.com/sindresorhus/meow](https://github.com/sindresorhus/meow)
314 |
315 | [./try/try_meow.js](./try/try_meow.js)
316 | ``` js
317 | const meow = require('meow');
318 | // ...
319 | console.log(cli.help) // 定义帮助
320 | console.log(cli.input[0], cli.flags);
321 | // input[0] == hello
322 | (node try_meow.js hello -p true)
323 | ·
324 | // flags[p] == true or flags[p] == hello
325 | (node try_meow.js -p) or -p hello
326 | ```
327 |
328 | ### 配置文件
329 |
330 | [./translate-js/config/] 配置文档
331 |
332 | 使用了一个默认的 ``配置json``
333 |
334 | [./translate-js/config/defaultConfig.json](./translate-js/config/defaultConfig.json)
335 |
336 | 一般来说,从 ``export 函数参数`` 或 ``命令行参数`` 获取 用户使用参数
337 |
338 | 这个时候就要比较,这件事我觉得可以这样做·
339 |
340 | ``` js
341 | function setDefault(option, callback, args){
342 | return callback(option, args)
343 | }
344 |
345 | // 获取默认配置
346 | let args = require('defaultConfig.json')
347 |
348 | function fromTodo(tranFrom, args){
349 | if(tranFrom){
350 | args.from = tranFrom // 替换
351 | }
352 | return args.from // 返回
353 |
354 | // 命令行参数为例子 , f from 从什么语言
355 | const tranfrom = setDefault(cli.flag['f'],fromTodo, args)
356 |
357 | // 这个时候 tranfrom 就是 正确的值
358 |
359 | ```
360 |
361 | 特别要注意的⚠️
362 |
363 | ``第一点``,就是更换了默认 ``defaultConfig.json``
364 |
365 | 应该做好一个运行``配置文档``来``给予``其他需要配置的``代码文件使用``。
366 |
367 | writeJson.js
368 | ``` js
369 | const fs = require('mz/fs') // 异步的文件操作库
370 | module.exports = async function writeJson(jsonFile, jsonObj) {
371 | await fs.writeFile(jsonFile, JSON.stringify(jsonObj, null, 2))
372 | }
373 | ```
374 |
375 | [./translate-js/index.js#L74](./translate-js/index.js#L74)
376 | ``` js
377 | const configJson = __dirname+'/' //path/to/you/want
378 | await writeJson(configJson, defaultConfig) // 用 defaultConfig 写入 config.json
379 | ```
380 |
381 | ``第二点``, 所以那些需要配置参数的 ``文件`` 需要在
382 |
383 | ``await writeJson(configJson, defaultConfig)``
384 |
385 | 这行之后,``require()`` 使用
--------------------------------------------------------------------------------
/translate-js/License:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yobrave] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------