ant-tool / atool-l10n

🌍 localized message files generating automatic solution
46 stars 10 forks source link
i18n l10n l10n-helper react-intl translation

atool-l10n

automatical solution for generating localization resource using middlewares

Demo in React

Usage

Options


  Usage: atool-l10n [options]

  Options:

    -h, --help        output usage information
    -v, --version     output the version number
    --config <dir>    where is the config file, default is l10n.config.js

Middleware

atool-l10n middlewares will execute one by one, with parameter query and shared context

A middleware may looks like this:

export default function something(query) {
  this.getMeta();
  this.setResult();
  this.setOption();
  ...
}

Context

There are necessary operation and usefull methods on this context in the function

You can check the detail API via file

Built-in middlewares

parameter default description
sourcePattern 'i18n-messages/**/*.json' where the messages json files is, specified in babel-plugin-react-intl, array supported
parameter default description
source 'locales' where the local locales messages file is, file name is same as language name, eg: zh
skip true if add the id into translating skip array when all local locales messages for it is not empty
parameter default description
from 'defaultMessage' using which key of meta, eg: defaultMessage, id, description...
to 'zh' the language you want to save as
parameter default description
apiname 'iamatestmanx' apiname you applied for machine translation from youdao
apikey '2137553564' apikey you applied for machine translation from youdao

you can easily apply the apiname and apikey from youdao

parameter default description
from 'zh-cn' string, what languages you want to translate from
to 'en' string, what languages you want to translate to
tld 'cn' string, which TLD of Google Translate you want to use, form: translate.google.${tld}

use google-translate-api

parameter default description
from 'zh' can be an array, what languages you want to translate from
to 'en' can be an array, what languages you want to translate to
parameter default description
autoPick false auto pick the value of index [autoPick]
autoReduce ['local', 'meta'] auto reduce some options, the smallest index wins, values of the other index in the array will be delete
parameter default description
dest 'locales' save locales messages into where, message file named by language name