Browse Source

add custom config support for i18n build

master
filesite 3 weeks ago
parent
commit
67e7b91467
  1. 4
      i18n.mjs
  2. 2
      i18n/README.md
  3. 5
      test/i18n.test.mjs

4
i18n.mjs

@ -13,12 +13,12 @@ import common from './common.mjs'; @@ -13,12 +13,12 @@ import common from './common.mjs';
class I18N {
//构造函数,设置默认配置
constructor(defaultLang, templateDir, langDir, buildDir, configFilename) {
constructor(configFilename, defaultLang, templateDir, langDir, buildDir) {
this.configFile = typeof(configFilename) != 'undefined' && configFilename ? configFilename : 'config.json';
this.defaultLang = typeof(defaultLang) != 'undefined' && defaultLang ? defaultLang : 'en';
this.templateDir = typeof(templateDir) != 'undefined' && templateDir ? templateDir : './public/template/';
this.langDir = typeof(langDir) != 'undefined' && langDir ? langDir : './i18n/';
this.buildDir = typeof(buildDir) != 'undefined' && buildDir ? buildDir : './public/';
this.configFile = typeof(configFilename) != 'undefined' && configFilename ? configFilename : 'config.json';
}
//从模板文件中解析语言占位变量,并生成语言包文件

2
i18n/README.md

@ -44,7 +44,7 @@ npm run i18n_init @@ -44,7 +44,7 @@ npm run i18n_init
### 使用语言包生成html文件
```
npm run i18n_build [语言代号]
npm run i18n_build [语言代号] [config文件名]
```
如果不传参数“语言代号”,则生成i18n/目录下的所有已配置语言对应的html文件。

5
test/i18n.test.mjs

@ -18,9 +18,10 @@ let initTest = async function(t) { @@ -18,9 +18,10 @@ let initTest = async function(t) {
};
let buildTest = async function(t) {
const i18n = new I18N();
let lang = process.argv[3];
let configFilename = process.argv[4];
if (!configFilename) {configFilename = 'config.json';}
const i18n = new I18N(configFilename);
const res = await i18n.build(lang);
assert.ok(res);

Loading…
Cancel
Save