This commit is contained in:
zhaoyingbo 2022-12-20 00:02:24 +00:00
parent 45d235b589
commit 3394c1b4b3
11 changed files with 1359 additions and 28 deletions

View File

@ -0,0 +1,12 @@
{
"name": "canary",
"image": "reg.yingbo.im:333/dev-container/base16:latest",
"containerUser": "node",
"forwardPorts": [5173],
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens",
"unifiedjs.vscode-mdx"
]
}

1
.npmrc Normal file
View File

@ -0,0 +1 @@
registry=https://pkgs.d.xiaomi.net/artifactory/api/npm/mi-npm/

17
dist/export.js vendored
View File

@ -16,18 +16,21 @@ const utils_1 = require("./utils");
function exportMessages(file, lang) {
const CONFIG = utils_1.getProjectConfig();
const langs = lang ? [lang] : CONFIG.distLangs;
const srcLangObjs = utils_1.getTargetLangObjs(CONFIG.srcLang);
langs.map(lang => {
const allMessages = utils_1.getAllMessages(CONFIG.srcLang);
const existingTranslations = utils_1.getAllMessages(lang, (message, key) => !/[\u4E00-\u9FA5]/.test(allMessages[key]) || allMessages[key] !== message);
const messagesToTranslate = Object.keys(allMessages)
.filter(key => !existingTranslations.hasOwnProperty(key))
// 已经存在的翻译文案
const targetLangObjs = utils_1.getTargetLangObjs(lang, (message, key) => !/[\u4E00-\u9FA5]/.test(srcLangObjs[key]) || srcLangObjs[key] !== message);
// 待翻译的文案
const messagesToTranslate = Object.keys(srcLangObjs)
.filter(key => !targetLangObjs.hasOwnProperty(key))
.map(key => {
let message = allMessages[key];
// 把中文文案直接写回对应的文案
let message = srcLangObjs[key];
message = JSON.stringify(message).slice(1, -1);
return [key, message];
targetLangObjs[key] = message;
});
if (messagesToTranslate.length === 0) {
console.log('All the messages have been translated.');
console.log('未发现未翻译文案');
return;
}
const content = d3_dsv_1.tsvFormatRows(messagesToTranslate);

2
dist/export.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,OAAO,CAA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AAC,EAAE;YACT,iBAAiB;YACjB,IAAI,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;YAC9B,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YAC9C,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAA;QAC/B,CAAC,CAAC,CAAA;QAEJ,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YACvB,OAAM;SACP;QAED,MAAM,OAAO,GAAG,sBAAa,CAAC,mBAAmB,CAAC,CAAA;QAClD,MAAM,UAAU,GAAG,IAAI,IAAI,YAAY,IAAI,EAAE,CAAA;QAC7C,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QACrC,OAAO,CAAC,GAAG,CAAC,YAAY,mBAAmB,CAAC,MAAM,cAAc,CAAC,CAAA;IACnE,CAAC,CAAC,CAAA;AACJ,CAAC;AAEQ,wCAAc"}

View File

@ -208,9 +208,8 @@ function extractAll({ dirPath, prefix }) {
const dir = dirPath || './src';
// 去除I18N前缀后续全局加
const langsPrefix = prefix ? prefix.replace(/^I18N\./, '') : null;
// 获取目标文件下全部中文文案
// 获取目标文件下全部中文文案,并按文件夹归类
const allTargetStrs = findAllChineseText(dir);
console.log(allTargetStrs);
if (allTargetStrs.length === 0) {
console.log(utils_1.highlightText('没有发现可替换的文案!'));
return;
@ -223,7 +222,9 @@ function extractAll({ dirPath, prefix }) {
console.log(`\n当前使用 ${utils_1.highlightText(origin)} 作为key值的翻译源`);
}
console.log('即将截取每个中文文案的前5位翻译生成key值并替换中...\n');
// 对当前文件进行文案key生成和替换
/**
* 对当前文件进行文案key生成和替换
*/
const generateKeyAndReplace = (item) => __awaiter(this, void 0, void 0, function* () {
const { texts, file: filePath } = item;
console.log(`${utils_1.highlightText(filePath)} 替换中...`);
@ -294,6 +295,11 @@ function extractAll({ dirPath, prefix }) {
utils_1.failInfo(e.message);
});
});
/**
* 遍历每个文件夹中的中文文案
* 不并发处理的原因是不同文件的相同文案需要尽可能指向同一个文件以减少整体国际化文件体积
* 每个文件处理的时候需要判定之前处理过的文件的文案列表
*/
allTargetStrs
.reduce((prev, current) => {
return prev.then(() => {

File diff suppressed because one or more lines are too long

2
dist/import.js vendored
View File

@ -57,7 +57,7 @@ function writeMessagesToFile(messages, file, lang) {
}
function importMessages(file, lang) {
let messagesToImport = getMessagesToImport(file);
const allMessages = utils_1.getAllMessages(CONFIG.srcLang);
const allMessages = utils_1.getTargetLangObjs(CONFIG.srcLang);
messagesToImport = _.pickBy(messagesToImport, (message, key) => allMessages.hasOwnProperty(key));
const keysByFiles = _.groupBy(Object.keys(messagesToImport), key => key.split('.')[0]);
const messagesByFiles = _.mapValues(keysByFiles, (keys, file) => {

2
dist/import.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"import.js","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC;IAC1B,eAAe,EAAE;QACf,MAAM,EAAE,UAAU;KACnB;CACF,CAAC,CAAC;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,4BAA4B;AAC5B,mCAAsC;AACtC,mCAAqE;AAErE,MAAM,MAAM,GAAG,wBAAgB,EAAE,CAAC;AAElC,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,qBAAY,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACtD,IAAI;YACF,8CAA8C;YAC9C,qCAAqC;YACrC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;S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Ac"}

33
dist/utils.js vendored
View File

@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.highlightText = exports.failInfo = exports.successInfo = exports.translateWithBaiduPinyin = exports.getTranslateOriginType = exports.lookForFiles = exports.flatten = exports.findMatchKey = exports.translateText = exports.getProjectConfig = exports.getAllMessages = exports.withTimeout = exports.retry = exports.traverse = exports.getLangDir = exports.getCanaryDir = void 0;
exports.highlightText = exports.failInfo = exports.successInfo = exports.translateWithBaiduPinyin = exports.getTranslateOriginType = exports.lookForFiles = exports.flatten = exports.findMatchKey = exports.translateText = exports.getProjectConfig = exports.getTargetLangObjs = exports.withTimeout = exports.retry = exports.traverse = exports.getLangDir = exports.getCanaryDir = void 0;
/**
* @author linhuiw
* @desc 工具方法
@ -90,28 +90,35 @@ function traverse(obj, cb) {
}
exports.traverse = traverse;
/**
* 获取所有文案
* 获取指定语言的全部文案
* @return 示例{ 'common.test': '测试', 'common.chinese': '中国' }
*/
function getAllMessages(lang, filter = (message, key) => true) {
const srcLangDir = getLangDir(lang);
let files = fs.readdirSync(srcLangDir);
files = files.filter(file => file.endsWith('.ts') && file !== 'index.ts').map(file => path.resolve(srcLangDir, file));
const allMessages = files.map(file => {
function getTargetLangObjs(lang, filter = (message, key) => true) {
// 是否是JS项目
const { isJsProj } = getProjectConfig();
// 指定语言配置文件夹
const langDir = getLangDir(lang);
// 过滤文件并生成对应文件路径
let files = fs.readdirSync(langDir);
const tsFilter = file => file.endsWith('.ts') && file !== 'index.ts';
const jsFilter = file => file.endsWith('.js') && file !== 'index.js';
files = files.filter(isJsProj ? jsFilter : tsFilter).map(file => path.resolve(langDir, file));
// 读取所有文件的文案配置并拍平
const langObjs = files.map(file => {
const { default: messages } = require(file);
const fileNameWithoutExt = path.basename(file).split('.')[0];
const fileName = path.basename(file).split('.')[0];
const flattenedMessages = {};
console.log(fileNameWithoutExt, messages);
traverse(messages, (message, path) => {
const key = fileNameWithoutExt + '.' + path;
traverse(messages, (message, keyPath) => {
const key = fileName + '.' + keyPath;
if (filter(message, key)) {
flattenedMessages[key] = message;
}
});
return flattenedMessages;
});
return Object.assign({}, ...allMessages);
return Object.assign({}, ...langObjs);
}
exports.getAllMessages = getAllMessages;
exports.getTargetLangObjs = getTargetLangObjs;
/**
* 重试方法
* @param asyncOperation

2
dist/utils.js.map vendored

File diff suppressed because one or more lines are too long

1302
yarn.lock Normal file

File diff suppressed because it is too large Load Diff