代码拉取完成,页面将自动刷新
同步操作将从 zyronon/typing-word 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import { src, dest } from 'gulp';
import through from 'through2';
import * as XLSX from 'xlsx';
import * as path from 'path';
function excel2json() {
let json = {};
const stream = through.obj(function(file, encode, cb) {
if (!file.isBuffer()) {
return cb(null, file);
}
const workbook = XLSX.read(file.contents);
// const excelData = XLSX.utils.sheet_to_json(
// workbook.Sheets[workbook.SheetNames[0]],
// );
const excelData = XLSX.utils.sheet_to_json(workbook.Sheets['Sheet1']);
json = excelData.reduce((result, current) => {
let newCurrent = {};
for (var key in current) {
var letterPattern = /[a-zA-Z]+/g;
var matches = key.match(letterPattern);
if (matches) {
var string = matches[0].toLocaleLowerCase();
newCurrent[string] = current[key].replace(/@{/g, '{');
}
}
result[newCurrent.key] = {};
result[newCurrent.key]['en'] = newCurrent.en || '';
result[newCurrent.key]['zh'] = newCurrent.zh || '';
result[newCurrent.key]['id'] = newCurrent.id || '';
result[newCurrent.key]['tw'] = newCurrent.tw || '';
result[newCurrent.key]['th'] = newCurrent.th || '';
result[newCurrent.key]['ru'] = newCurrent.ru || '';
result[newCurrent.key]['vi'] = newCurrent.vi || '';
result[newCurrent.key]['es'] = newCurrent.es || '';
result[newCurrent.key]['pt'] = newCurrent.pt || '';
result[newCurrent.key]['ja'] = newCurrent.ja || '';
result[newCurrent.key]['uk'] = newCurrent.uk || '';
result[newCurrent.key]['ko'] = newCurrent.ko || '';
result[newCurrent.key]['de'] = newCurrent.de || '';
result[newCurrent.key]['fr'] = newCurrent.fr || '';
return result;
}, json);
file.contents = Buffer.from(JSON.stringify(json, null, '\t'));
file.path = path.join(file.base, 'i18n.json');
cb(null, file);
});
return stream;
}
// 将翻译好的excel写入json
function i18nwrite() {
return src(['./src/locales/i18n.xlsx'])
.pipe(excel2json())
.pipe(dest('src/locales'));
}
export { i18nwrite };
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。