中文 | English
🌎 An auto-i18n tool, based on kiwi+google_cn
1.Install
npm install sultana-inter
- create
i18n.json
in your project path. it looks like:
{
"include": ["src/**/*.(ts*|js*)"],
"exclude": ["**/i18n/**","**/test/*","**/*.test.*"],
"importPath":"./src/i18n/language",
"importFormat": {
"ts":"import {i18n_lang_package,i18n_lang_format} from \"{{importPath}}\";",
"js":"const {i18n_lang_package,i18n_lang_format} = reuqire(\"{{importPath}}\");",
"html":"<script src=\"{{importPath}}/index.js\"></script>"
},
"translate":{
"from":"zh",
"to":"en"
},
"templateFunction":"i18n_lang_format",
"templateObj":"i18n_lang_package",
"exportPath": "./src/i18n/{{lang}}/{{filename}}.js",
"ignoreComments": "@i18n-ignore",
"excludeDirName":["components","pages","constants","containers","models","services","src"],
"defaultDirName":"common"
}
- Exec i18n command and input your project directory.
su-inter -p /path/to/your/project/
-
include
string[]
The included folder matches the
micromatch
syntax.Ex:
["src/**/*.(ts*|js*)"]
-
exclude
string[]
The excluded folder matches the
·
micromatch` syntax.Ex:
["**/i18n/**","**/test/*"]
-
importPath
string
Path or file name import in your code.
Ex:
"./src/i18n/language"
-
importFormat
-
ts
string
importing template of*.ts*
files,"{{importpath}}" is used as the template variable of configurationimportpath
.Ex:
"import {i18n_lang_package,i18n_lang_format} from \"{{importPath}}\";"
-
js
string
*.js*
filesEx:
"const {i18n_lang_package,i18n_lang_format} = reuqire(\"{{importPath}}\");"
-
html
string
*.html
filesEx:
"<script src=\"{{importPath}}/index.js\"></script>"
-
-
translate
- from
string
translation configuration,original language.All language formats are subject to [languages supported by Google translation] (https://cloud.google.com/translate/docs/languages). Ex: 'zh'. - to
string
The requirements are the same as above.Ex:en
.
- from
-
templateFunction
string
The function name used for formatting, such as
"I18N. Format"
will be compiled intoI18N. Format (I18N. Lang.xxx, {val1: XXX, val2: XXX})})
-
templateObj
string
The variable name of the language pack in use, such as configuration
"I18N. Lang"
, will be compiled intoI18N. Lang.xxx
-
exportPath
string
The output language directory uses
{{Lang}
and{{filename}
as the language folder name and file name.Ex:
"./src/i18n/{{lang}}/{{filename}}.js"
-
ignoreComments
string
Ignore flag. When configuring '@ I18N ignore', translation will be ignored in the following situations:
// @i18n-ignore const title="我和我的祖国"
-
excludeDirName
string[]
The tool uses the folder name as
{{filename}}
of the exportpath. Configure this to ignore the configured text when recursively looking for folders.Ex:
["components","models","services","src"]
-
defaultDirName
string
This configuration item is used instead of
{{filename}}
when there is no suitable folder name.Ex:
common
- ignoreComments
- importFomat html header