|
@@ -1,45 +1,22 @@
|
|
|
// import allTrans from './src/locales/lang/zh-CN/**/*.ts';
|
|
// import allTrans from './src/locales/lang/zh-CN/**/*.ts';
|
|
|
import { recursiveReaddir } from 'https://deno.land/x/recursive_readdir/mod.ts';
|
|
import { recursiveReaddir } from 'https://deno.land/x/recursive_readdir/mod.ts';
|
|
|
import { join, dirname, extname, basename } from 'https://deno.land/std/path/mod.ts';
|
|
import { join, dirname, extname, basename } from 'https://deno.land/std/path/mod.ts';
|
|
|
-import { ensureDir } from 'https://deno.land/std/fs/mod.ts';
|
|
|
|
|
import { flatten } from 'https://deno.land/x/flatten@1.1.0/mod.ts';
|
|
import { flatten } from 'https://deno.land/x/flatten@1.1.0/mod.ts';
|
|
|
|
|
|
|
|
-const zhPath = 'src/locales/lang/zh-CN';
|
|
|
|
|
-const jaPath = 'src/locales/lang/ja';
|
|
|
|
|
-const transZHFiles = (await recursiveReaddir(join('.', zhPath))).filter(
|
|
|
|
|
|
|
+const currentPath = 'src/locales/lang/ja';
|
|
|
|
|
+const currentLang = 'ja';
|
|
|
|
|
+const transFiles = (await recursiveReaddir(join('.', currentPath))).filter(
|
|
|
(file: string) => extname(file) === '.ts',
|
|
(file: string) => extname(file) === '.ts',
|
|
|
);
|
|
);
|
|
|
-const transJAFiles = (await recursiveReaddir(join('.', jaPath))).filter(
|
|
|
|
|
- (file: string) => extname(file) === '.ts',
|
|
|
|
|
-);
|
|
|
|
|
-await ensureDir('trans/zh');
|
|
|
|
|
-await ensureDir('trans/ja');
|
|
|
|
|
-
|
|
|
|
|
-const writeJSON = async (element, dir = '') => {
|
|
|
|
|
- console.log('src', element);
|
|
|
|
|
- const mod = (await import(`./${element}`)).default;
|
|
|
|
|
- console.log('src', mod);
|
|
|
|
|
- const Jfile = JSON.stringify(mod);
|
|
|
|
|
- const fileName = basename(element, '.ts');
|
|
|
|
|
- const wDir = dir || 'trans/zh/';
|
|
|
|
|
- // console.log('fileName', fileName);
|
|
|
|
|
- await Deno.writeTextFile(`${wDir}${fileName}.json`, Jfile);
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-// transZHFiles.forEach((element) => {
|
|
|
|
|
-// writeJSON(element, 'trans/zh/');
|
|
|
|
|
-// });
|
|
|
|
|
-// transJAFiles.forEach((element) => {
|
|
|
|
|
-// writeJSON(element, 'trans/ja/');
|
|
|
|
|
-// });
|
|
|
|
|
-
|
|
|
|
|
-const allZH = transZHFiles.map(async (src) => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+const allTrans = transFiles.map(async (src) => {
|
|
|
const mod = (await import(`./${src}`)).default;
|
|
const mod = (await import(`./${src}`)).default;
|
|
|
|
|
+
|
|
|
const surfix = extname(src);
|
|
const surfix = extname(src);
|
|
|
const fileName = basename(src, surfix);
|
|
const fileName = basename(src, surfix);
|
|
|
const suFolder = basename(dirname(src));
|
|
const suFolder = basename(dirname(src));
|
|
|
const data = {};
|
|
const data = {};
|
|
|
- if (suFolder == 'zh-CN') {
|
|
|
|
|
|
|
+ if (suFolder == currentLang) {
|
|
|
{
|
|
{
|
|
|
data[fileName] = mod;
|
|
data[fileName] = mod;
|
|
|
}
|
|
}
|
|
@@ -48,10 +25,14 @@ const allZH = transZHFiles.map(async (src) => {
|
|
|
sub[fileName] = mod;
|
|
sub[fileName] = mod;
|
|
|
data[suFolder] = sub;
|
|
data[suFolder] = sub;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return data;
|
|
return data;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-const obj = await Promise.all(allZH);
|
|
|
|
|
-const flatObj = flatten(Object.assign({}, ...obj));
|
|
|
|
|
|
|
+const obj = await Promise.all(allTrans);
|
|
|
|
|
+
|
|
|
|
|
+const lastObj = obj.map((item) => flatten(item));
|
|
|
|
|
+
|
|
|
|
|
+const last = Object.assign({}, ...lastObj);
|
|
|
|
|
|
|
|
-await Deno.writeTextFile(`zh.json`, JSON.stringify(flatObj));
|
|
|
|
|
|
|
+await Deno.writeTextFile(`${currentLang}.json`, JSON.stringify(last));
|