UNPKG

@c-sheep/i18n-extract-cli

Version:

这是一款能够自动将代码里的中文转成i18n国际化标记的命令行工具。当然,你也可以用它实现将中文语言包自动翻译成其他语言。适用于vue2、vue3和react

77 lines (76 loc) 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.importCode = void 0; // 参数path,在生成配置文件时需要展示在文件里,所以这里去掉eslint校验 // eslint-disable-next-line @typescript-eslint/no-unused-vars function getCustomizeKey(key, path) { key = key.replace(/\./g, "_").replace(/ /g, "").replace(/\[|\]/g, "_"); path = path === null || path === void 0 ? void 0 : path.replace("./", ""); const [type, ...fullPathArr] = (path || "").slice(4, -4).split("/"); if (type === "views") { const [moduleName] = fullPathArr; return `${moduleName}.${key}`; } return `common.${key}`; } exports.importCode = `import i18n from '@locales/'\nconst $t = i18n.global.t`; function getCommonRule() { return { caller: "", functionName: "$t", customizeKey: getCustomizeKey, importDeclaration: exports.importCode, }; } const config = { input: "src", output: "", secretId: "", secretKey: "", exclude: ["**/node_modules/**/*"], rules: { js: getCommonRule(), ts: getCommonRule(), cjs: getCommonRule(), mjs: getCommonRule(), jsx: { ...getCommonRule(), functionSnippets: "", }, tsx: { ...getCommonRule(), functionSnippets: "", }, vue: { caller: "", importDeclaration: exports.importCode, functionNameInTemplate: "$t", functionNameInScript: "$t", customizeKey: getCustomizeKey, tagOrder: ["template", "scriptSetup", "script", "style"], }, }, prettier: { semi: false, singleQuote: true, }, incremental: false, localePath: "./locales/module", localeFileType: "json", translateJsonPath: "./locales/auto-translate", excelPath: "./locales/excel/locals.xlsx", transferPath: "./locales/translate", locales: ["en", "zh-tw"], globalRule: { ignoreMethods: ["defineProps"], }, defaultKey: "zh-cn", sortData: ["key", "local", "zh"], jsonVarFormat: (a) => `{${a}}`, // 参数currentFileKeyMap和currentFilePath,在生成配置文件时需要展示在文件里,所以这里去掉eslint校验 // eslint-disable-next-line @typescript-eslint/no-unused-vars adjustKeyMap(allKeyValue) { return allKeyValue; }, }; exports.default = config;