create-iking-admin
Version:
金合技术中台脚手架
44 lines (42 loc) • 1.31 kB
text/typescript
/*
* @Author: wfl
* @LastEditors: wfl
* @description:
* @updateInfo:
* @Date: 2022-10-13 15:13:54
* @LastEditTime: 2022-10-25 15:49:22
*/
import axios from 'axios';
import fs from 'fs';
export const setI18n = (VITE_GLOB_API_URL) => {
try {
let customStrZH = '';
let customStrEN = '';
console.info('[获取国际化配置]');
axios.get(`${VITE_GLOB_API_URL}/server/i18n`).then((res: any) => {
if (res.data.success) {
res.data.data.forEach(({ items }) => {
items &&
items.forEach(({ key, zh, en }) => {
customStrZH += `${key}: '${zh}',`;
customStrEN += `${key}: '${en}',`;
});
});
}
console.info('[写入国际化配置]');
// const zhjs = fs.readFileSync(`${__dirname}/src/locales/lang/zh-CN/custom.ts`)
fs.writeFileSync(
`${__dirname}/src/locales/lang/zh-CN/custom.ts`,
`export default {${customStrZH}}`,
);
// const enjs = fs.readFileSync(`${__dirname}/src/locales/lang/zh-CN/custom.ts`)
fs.writeFileSync(
`${__dirname}/src/locales/lang/en/custom.ts`,
`export default {${customStrEN}}`,
);
console.info('[写入完成]');
});
} catch (error) {
console.info('[国际化设置写入错误]: ', error);
}
};