i18n-transform-cli
Version:
这是一款能够自动将代码里的中文转成i18n国际化标记的命令行工具。当然,你也可以用它实现将中文语言包自动翻译成其他语言。适用于vue2、vue3和react
65 lines (64 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// 参数path,在生成配置文件时需要展示在文件里,所以这里去掉eslint校验
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getCustomizeKey(key, path) {
return key;
}
function getCommonRule() {
return {
caller: '',
functionName: 't',
customizeKey: getCustomizeKey,
importDeclaration: 'import { t } from "i18n"',
};
}
const config = {
input: 'src',
output: '',
exclude: ['**/node_modules/**/*'],
rules: {
js: getCommonRule(),
ts: getCommonRule(),
cjs: getCommonRule(),
mjs: getCommonRule(),
jsx: {
...getCommonRule(),
functionSnippets: '',
},
tsx: {
...getCommonRule(),
functionSnippets: '',
},
vue: {
caller: 'this',
functionNameInTemplate: '$t',
functionNameInScript: '$t',
customizeKey: getCustomizeKey,
importDeclaration: '',
tagOrder: ['template', 'script', 'style'],
},
},
prettier: {
semi: false,
singleQuote: true,
},
incremental: false,
skipExtract: false,
localePath: './locales/zh.json',
localeFileType: 'json',
excelPath: './locales.xlsx',
excelFieldPath: './locales-field.xlsx',
exportExcel: false,
skipTranslate: false,
locales: ['en'],
globalRule: {
ignoreMethods: [],
},
// 参数currentFileKeyMap和currentFilePath,在生成配置文件时需要展示在文件里,所以这里去掉eslint校验
// eslint-disable-next-line @typescript-eslint/no-unused-vars
adjustKeyMap(allKeyValue, currentFileKeyMap, currentFilePath) {
return allKeyValue;
},
};
exports.default = config;