Code Monkey home page Code Monkey logo

i18n-translate-tool's Introduction

一个国际化翻译工具

原理是借用谷歌翻译的api 读取 esm 的待翻译js 文件,进行翻译

全局安装

npm i -g i18n-translate-tool

测试安装是否成功

安装成功后,itt 会全局可用

itt -h

输入内容如下:

Options:
  -V, --version                output the version number
  -f, --file [file]            导入待翻译的文件以及目标语言
  -d, --dist [file]            输出翻译后的结果,默认会覆盖源文件
  -p, --param [translate key]  取被翻译文件对象的 keys 或者 values (default: "keys")
  -h, --help                   display help for command

配置如下:

  • -f, --file 被翻译的文件

  • -d, --dist 国际化之后要生成的文件名(生成在当前目录)

  • -p, --param 取被翻译文件对象的 keys 或者 values (default: "keys")

-- -h, --help 帮助文档

快捷使用

默认 取 对象的 keys 做为翻译源

itt ./test/1.js

demo

要翻译文件名为 2.js 的文件 itt -f 2.js -p keys (-f 指定读取的文件,-p 指定取 该文件对象里的keys 做为翻译源)

2.js 文件内容如下

export default {
  '我是默认导出对象': '',
  '我是默认导出对象3': '',
  '我是默认导出对象2': '',
  '我是默认导出对象1': '',
}

export const a = {
  '你好': '',
  '我好': '',
}

结果如下:

export default {
  "我是默认导出对象": "I am the default export object",
  "我是默认导出对象3": "I am the default export object 3",
  "我是默认导出对象2": "I am the default export object 2",
  "我是默认导出对象1": "I am the default export object 1"
}

export const a = {
  "你好": "Hello",
  "我好": "I'm good"
}

后续开发计划

i18n-translate-tool's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.