forked from jonjia/vue-i18n-code-shift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
3,794 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,5 @@ | ||
# Logs | ||
logs | ||
*.log | ||
/node_modules | ||
.DS_Store | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
trailingComma: 'es5', | ||
tabWidth: 2, | ||
semi: true, | ||
singleQuote: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "findChineseText", | ||
"program": "${workspaceFolder}/src/utils/findChineseText.js", | ||
"skipFiles": ["<node_internals>/**"] | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "extract", | ||
"program": "${workspaceFolder}/src/commands/extract/index.js", | ||
"skipFiles": ["<node_internals>/**"] | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "replace", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/src/commands/replace/index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "export", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/src/commands/export/index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "import", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/src/commands/import/index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "moveRules", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/src/commands/moveRules/index.js", | ||
"resolveSourceMapLocations": [ | ||
"${workspaceFolder}/**", | ||
"!**/node_modules/**" | ||
] | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "check", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/src/commands/check/index.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# vue-i18n-code-shift | ||
|
||
vue 项目国际化全流程解决方案: 一个命令行工具,对代码里的中文文案一键完成提取、替换、翻译、导入、导出等,告别手动操作 | ||
|
||
## 功能 | ||
|
||
- **一键提取并替换中文文案** | ||
- **导出未翻译的文案** | ||
- **导入翻译好的文案** | ||
|
||
## 安装 | ||
|
||
```shellscript | ||
npm install -g vue-i18n-code-shift | ||
``` | ||
|
||
## 命令 | ||
|
||
### `vics init` | ||
|
||
初始化项目,生成配置文件 `vics-config.json` | ||
|
||
```js | ||
{ | ||
// vics文件根目录,用于放置提取的langs文件 | ||
vicsDir: './.vics', | ||
|
||
// 配置文件目录,若调整配置文件,此处可手动修改 | ||
configFile: './.vics/vics-config.json', | ||
|
||
// 语言目录名,注意连线和下划线 | ||
srcLang: 'zh-CN', | ||
distLangs: ['en'], | ||
langMap: { | ||
'en_US': 'en', | ||
'en-US': 'en', | ||
'en': 'en', | ||
}, | ||
|
||
// 百度翻译 | ||
baiduAppid: '', | ||
baiduKey: '', | ||
|
||
// I18N import 语句,请按照自己项目情况配置 | ||
importI18N: "import I18N from '@/i18n';", | ||
// import 语句后缀,用于判断是否已经引入过 | ||
i18nPath: '@/i18n', | ||
|
||
// 可跳过的文件夹名或者文加名,比如docs、mock等 | ||
ignoreDir: [], | ||
ignoreFile: [], | ||
|
||
// 导出未翻译的文案,Excel 列的配置 | ||
exportColConfig: ['export_path', '业务线', 'business_key', '描述(字典值)', '语料类型', '最长字符', '首字母大写', '语料说明图', 'translatable', 'formatted', 'zh_CN'], | ||
// 导出未翻译的文案,业务线、key、文案在 Excel 中列的索引 | ||
exportColIndexMap: { | ||
businessLine: 1, | ||
key: 3, | ||
text: 10, | ||
}, | ||
// 导入翻译好的文案,key、文案在 Excel 中列的索引 | ||
importColIndexMap: { | ||
key: 4, | ||
text: 12, | ||
}, | ||
// 语料平台 xlsx 文件配置,列从 0 开始 | ||
checkColIndexMap: { | ||
key: 3, // key 所在列 | ||
'zh-CN': 11, // 中文所在列 | ||
en: 12, // 英文所在列 | ||
}, | ||
// 语料文件 prettier 配置 | ||
prettierConfig: {}, | ||
} | ||
``` | ||
|
||
### `vics one` | ||
|
||
**一键提取并替换**指定文件夹、指定层级(默认为 0)下的所有中文文案,可以指定语料文件(默认为指定文件夹名字) | ||
|
||
```shellscript | ||
vics one [dirPath] [level] [langFilename] | ||
``` | ||
|
||
### `vics extract` | ||
|
||
**提取**指定文件夹、指定层级(默认为 0)下的所有中文文案,可以指定语料文件(默认为指定文件夹名字) | ||
|
||
```shellscript | ||
vics extract [dirPath] [level] [langFilename] | ||
``` | ||
|
||
### `vics replace` | ||
|
||
**替换**指定文件夹、指定层级(默认为 0)下的所有中文文案,可以指定语料文件(默认为指定文件夹名字) | ||
|
||
```shellscript | ||
vics replace [dirPath] [level] [langFilename] | ||
``` | ||
|
||
### `vics sync` | ||
|
||
**同步**各种语言的文案,使用百度翻译 **mock** 语料 | ||
|
||
```shellscript | ||
vics sync | ||
``` | ||
|
||
### `vics export` | ||
|
||
**导出**未翻译的文案 | ||
|
||
```shellscript | ||
# 导出指定语言的中文文案,lang取值为配置中distLangs值(lang 参数必填),如 en 就是导出还未翻译成英文的中文文案。可以指定业务线和产物文件名 | ||
# 导出范围:range // 0 未翻译,2 全部 | ||
vics export [lang] [range] [businessLine] [outputFilename] | ||
``` | ||
|
||
### `vics import` | ||
|
||
将翻译好的文案,**导入**到项目中 | ||
|
||
```shellscript | ||
# 导入送翻后的文案 | ||
vics import [lang] [filePath] | ||
``` | ||
|
||
### `vics moveRules` | ||
|
||
将 rules 从 data 移动到 computed,用来解决 rules 多语言不生效问题 | ||
|
||
```shellscript | ||
# 将 rules 从 data 移动到 computed | ||
vics moveRules [dir/file...] | ||
``` | ||
|
||
### `vics check` | ||
|
||
比较翻译平台管理的语料、代码中使用的语料之间的差异 | ||
|
||
```shellscript | ||
# 校验对比语料 | ||
vics check [filePath] | ||
``` | ||
|
||
语料平台 xlsx 文件配置,列从 0 开始,编辑 vics-config.json checkColIndexMap 字段 | ||
|
||
```shellscript | ||
checkColIndexMap: { | ||
key: 3, // key 所在列 | ||
'zh-CN': 11, // 中文所在列 | ||
en: 12, // 英文所在列 | ||
} | ||
``` | ||
|
||
## vics 解决了哪些问题 | ||
|
||
- 解决 vue 项目国际化过程中,中文文案手动替换费时费力问题 | ||
- 在翻译过程中,可以使用 vics 命令行自动提取未翻译中文词汇,导出成 Excel 方便与翻译同学协作。针对翻译同学还没有返回翻译文案的期间,可以使用 vics 的 sync 和 mock 功能,先临时翻译成对应语言,节省文案调整时间 | ||
- 国际化文案翻译完成后,可以使用 vics 的 import 命令,一键导入到项目文件内 | ||
- 比较翻译平台管理的语料、代码中使用的语料之间的差异,主要提供给测试同学使用 | ||
|
||
## Authors | ||
|
||
- **[jonjia](https://github.com/jonjia)** | ||
- Inspired by **[kiwi](https://github.com/alibaba/kiwi)** | ||
|
||
## License | ||
|
||
- MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "vue-i18n-code-shift", | ||
"version": "1.0.0", | ||
"description": "vue 项目国际化全流程解决方案: 一个命令行工具,对代码里的中文文案一键完成提取、替换、翻译、导入、导出等,告别手动操作", | ||
"main": "src/index.js", | ||
"repository": "[email protected]:jonjia/vue-i18n-code-shift.git", | ||
"author": "jonjia <[email protected]>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"vue", | ||
"i18n", | ||
"codemod", | ||
"codeshift", | ||
"tool" | ||
], | ||
"bin": { | ||
"vics": "src/index.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jonjia/vue-i18n-code-shift/issues" | ||
}, | ||
"homepage": "https://github.com/jonjia/vue-i18n-code-shift", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"chalk": "^4.1.1", | ||
"commander": "^7.2.0", | ||
"eslint": "^7.26.0", | ||
"fs-extra": "^10.0.0", | ||
"inquirer": "^8.0.0", | ||
"lodash": "^4.17.21", | ||
"node-xlsx": "^0.16.1", | ||
"ora": "^5.4.0", | ||
"prettier": "^2.3.0", | ||
"randomstring": "^1.2.1", | ||
"slash2": "^2.0.0", | ||
"typescript": "^4.2.4", | ||
"vue-template-compiler": "^2.6.12" | ||
} | ||
} |
Oops, something went wrong.