
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
i18n-auto-transformer
Advanced tools
一款能够让你的中文项目一键完成 i18n 国际化功能改造的命令行工具,支持多次增量提取、缓存、语言包补全。执行一次命令即可让任意 App 支持国际化,丝滑开发。
js
, ts
, react
项目i18n
调用函数,并将提取到的中文存入 zh-CN.json
语言包中i18n
调用函数的默认实现i18n
的调用方法名、导入路径、语言包的存放位置i18n
调用函数的实现,方便结合第三方国际化方案console.log
中的中文i18n-disable-file
i18n-disable
i18n-disable-line
i18n-disable-next-line
等多种注释,跳过中文提取glob
语法配置忽略部分文件、文件夹的中文提取prettier
格式化代码key
值npm i -D i18n-auto-transformer
执行 npx i18n run
,本工具将自动完成提取中文、翻译语言、生成 i18n
函数、生成语言 JSON
文件、将代码中的中文替换为 i18n
函数调用等全部任务
检查翻译后的 JSON
文件,校验翻译准确性、调整大小写、空格,检查生成的代码正确性
提交修改,完成项目国际化
i18n run
核心命令,一键完成国际化提取、翻译、替换。
开发流程:
i18n run
命令,会自动将所有中文提取出来,并替换成国际化函数i18n translate
将 zhCN.json
语言包文件中的内容增量翻译到其它语言包中。
常见的使用场景:
en.json
等国际化文件中的值为中文,删掉这些对应的中文键值后,执行 i18n translate
能够重新翻译这些部分。zhCN.json
文件添加了一些键值,需要同步到其它语言包中i18n init
生成初始化自定义配置文件 i18n.config.js
,支持各种自定义配置
i18n help
帮助命令,可以在界面中显示各个命令的解释,例如
$ npx i18n help
一款能够让你的中文项目一键完成 i18n 国际化功能改造的命令行工具,支持多次增量提取、缓存、英文补全,丝滑开发。
VERSION
i18n-auto-transformer/0.0.0 win32-x64 node-v14.19.3
USAGE
$ i18n [COMMAND]
TOPICS
plugins List installed plugins.
COMMANDS
help Display help for i18n.
init 初始化配置文件
plugins List installed plugins.
run 核心命令,一键完成国际化提取、翻译、替换。
translate 将 zhCN.json 文件中的内容增量翻译到其它国际化文件中。
$ npx i18n help run
核心命令,一键完成国际化提取、翻译、替换。
USAGE
$ i18n run
DESCRIPTION
核心命令,一键完成国际化提取、翻译、替换。
开发流程:
1. 接到新需求
2. 使用中文开发功能
3. 提交功能 commit
4. 执行 i18n run 命令,会自动将所有中文提取出来,并替换成国际化函数
5. 检查页面是否符合预期
6. 提交国际化 commit
7. 完成需求
8. 回到步骤 1
interface I18nConfigs {
/**
* 需要转换的文件位置,默认 `./src`
*/
codeDir?: string
/**
* i18n 文件存放路径,默认 `./src/i18n`
*/
i18nDir?: string
/**
* i18n 调用函数名,默认 `i18n`,即 `const text = i18n('示例')`
*/
i18nFn?: string
/**
* 引入 i18n 函数的路径,默认 `i18n`,即 `import $i18nFn$ from 'i18n'`
*/
i18nFrom?: string
/**
* 支持的语言列表,参考 https://cloud.google.com/translate/docs/languages,默认 `['zh-CN', 'en']`
*/
locales?: string[]
/**
* 排除某些文件或文件夹的翻译,参考 `glob` 的 `ignore` 配置
*/
ignore?: GlobOptions['ignore']
/**
* 跳过缓存,重新遍历所有文件
*/
skipCache?: boolean
/**
* 缓存文件的位置,默认 `./`
*/
cacheDir?: string
/**
* `prettier` 解析器,默认 `babel-ts`
*/
prettierParser?: PrettierOptions['parser']
/**
* `prettier` 路径,默认 `./.prettierrc`
*/
prettierPath?: string
/**
* `prettier` 配置对象,优先级高于 `prettierPath`,为 `false` 时则不进行格式化
*/
prettier?: Omit<PrettierOptions, 'parser'> | false
}
转换前
import React, { useReducer } from 'react'
// i18n-disable-next-line
const ignored = '忽略提取的中文'
export default function Example() {
const [time, addTime] = useReducer((a: number) => a + 1, 0)
return (
<div>
<button onClick={addTime}>按钮</button>
<p title="点击次数">{`已点击 ${time} 次`}</p>
</div>
)
}
转换后
import i18n from 'i18n'
import React, { useReducer } from 'react'
// i18n-disable-next-line
const ignored = '忽略提取的中文'
export default function Example() {
const [time, addTime] = useReducer((a: number) => a + 1, 0)
return (
<div>
<button onClick={addTime}>{i18n('按钮')}</button>
<p title={i18n('点击次数')}>{`${i18n('已点击 ')}${time}${i18n(
' 次'
)}`}</p>
</div>
)
}
本工具使用了 Google 翻译,因此需要先保证能够使用外网。若是 Clash for Windows
,可以开启 TUN Mode
实现全局代理
路径:General
- Service Mode
- Manage
安装插件, 安装完成后打开 TUN mode
开关
若是部分翻译超时,可以删除语言包中翻译失败的部分,或者直接删除语言包文件,执行 i18n translate
命令,便能基于中文 zhCN.json
文件进行重新翻译生成
支持通过注释来忽略,跟 eslint-ignore
类似
// i18n-disable-file
将忽略整个文件的中文翻译// i18n-disable-file
export const a = '啊啊'
export const b = '问问'
// i18n-disable-next-line
将忽略下一行的中文// i18n-disable-next-line
export const c = '萨达是'
// i18n-disable-line
将忽略本行的中文export const d = '啥第四十' // i18n-disable-line
/* i18n-disable */
将忽略两个注释中间的所有中文,若只有一个注释,则会忽略当前行直至文件结束的所有中文/* i18n-disable */
export const e = '爱仕达'
export const f = '撒旦'
/* i18n-disable */
FAQs
一款能够让你的中文项目一键完成 i18n 国际化功能改造的命令行工具,支持多次增量提取、缓存、英文补全,丝滑开发。
We found that i18n-auto-transformer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.