From 67e7b914675d89c5f2a1e3665291d997395eb6e6 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 5 Jul 2025 08:48:40 +0800 Subject: [PATCH] add custom config support for i18n build --- i18n.mjs | 4 ++-- i18n/README.md | 2 +- test/i18n.test.mjs | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/i18n.mjs b/i18n.mjs index fbb5853..6a33708 100644 --- a/i18n.mjs +++ b/i18n.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'; } //从模板文件中解析语言占位变量,并生成语言包文件 diff --git a/i18n/README.md b/i18n/README.md index 0f77a46..8a54947 100644 --- a/i18n/README.md +++ b/i18n/README.md @@ -44,7 +44,7 @@ npm run i18n_init ### 使用语言包生成html文件 ``` -npm run i18n_build [语言代号] +npm run i18n_build [语言代号] [config文件名] ``` 如果不传参数“语言代号”,则生成i18n/目录下的所有已配置语言对应的html文件。 diff --git a/test/i18n.test.mjs b/test/i18n.test.mjs index 6a91640..ea062eb 100644 --- a/test/i18n.test.mjs +++ b/test/i18n.test.mjs @@ -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);