| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- /**
- * 根据 zh.json + 旧项目 common/lang 生成 en.json
- * 用法: node scripts/build-en-locale.cjs
- */
- const fs = require('fs');
- const root = 'd:/project/2026项目/DeepAICloud';
- const zhPath = `${root}/src/locales/zh.json`;
- const enPath = `${root}/src/locales/en.json`;
- const oldEnPath = 'd:/project/2021项目/四维看看官网/webSite/common/lang/en.json';
- const oldZhPath = 'd:/project/2021项目/四维看看官网/webSite/common/lang/zh.json';
- const zh = JSON.parse(fs.readFileSync(zhPath, 'utf8'));
- const oldEn = JSON.parse(fs.readFileSync(oldEnPath, 'utf8'));
- const oldZh = JSON.parse(fs.readFileSync(oldZhPath, 'utf8'));
- const oldPcEn = oldEn.pc || {};
- const oldPcZh = oldZh.pc || {};
- function buildTextMap(zhObj, enObj, map = new Map()) {
- if (typeof zhObj === 'string' && typeof enObj === 'string' && zhObj.trim()) {
- map.set(zhObj, enObj);
- return map;
- }
- if (zhObj && enObj && typeof zhObj === 'object' && typeof enObj === 'object' && !Array.isArray(zhObj)) {
- for (const key of Object.keys(zhObj)) {
- if (enObj[key] !== undefined) buildTextMap(zhObj[key], enObj[key], map);
- }
- }
- return map;
- }
- const zhToEn = buildTextMap(oldPcZh, oldPcEn);
- const zhToEnManual = require('./en-translations-manual.cjs');
- const manual = {
- ...zhToEnManual,
- '欢迎使用深智云': 'Welcome to DeepAI Cloud',
- '语言': 'Language',
- '首页': 'Home',
- '设置': 'Settings',
- '操作成功': 'Operation successful',
- '失败': 'Failed',
- '加载中...': 'Loading...',
- '付款成功后5个工作日内发货,默认顺丰快递包邮':
- 'Ships within 5 business days after payment. SF Express shipping included.',
- '立即购买': 'Buy Now',
- '联系客服': 'Contact Support',
- '限时免费': 'Limited-time free',
- '咨询客服': 'Contact support',
- '¥{price}': '¥{price}',
- '您的购物车空空如也': 'Your cart is empty',
- '赶紧行动吧': 'Start shopping now',
- '四维时代商城': '4Dage Mall',
- '充分整合硬件、软件、增值服务,打造四维空间智能生态':
- 'Integrating hardware, software, and value-added services to build an intelligent 4D spatial ecosystem',
- '销售会员': 'Membership',
- '耗材配件': 'Consumables & Accessories',
- '增值服务': 'Value-added Services',
- '相机配件': 'Camera Accessories',
- '颜色': 'Color',
- '配件': 'Accessories',
- '简介': 'Introduction',
- '联系我们': 'Contact Us',
- '我的账户': 'My Account',
- '退出登录': 'Log Out',
- '常见问题': 'FAQ',
- '元/年': 'CNY/year',
- '云容量': 'Cloud Storage',
- '品牌信息': 'Brand Info',
- '优先计算': 'Priority Computing',
- '离线包下载': 'Offline Package Download',
- '立即体验': 'Try Now',
- '激光+全景': 'LiDAR + Panorama',
- '全景': 'Panorama',
- '激光': 'LiDAR',
- '免费10次': '10 free downloads',
- '{price}元/次': '{price} CNY/time',
- '我已支付': 'I have paid',
- '请在新窗口完成支付,完成后可点击下方按钮确认':
- 'Please complete payment in the new window, then click the button below to confirm.',
- '重新打开支付页': 'Reopen payment page',
- '同意《四维看看销售协议》': 'I agree to the 4DKanKan Sales Agreement',
- };
- function translateString(s) {
- if (typeof s !== 'string') return s;
- if (manual[s]) return manual[s];
- if (zhToEn.has(s)) return zhToEn.get(s);
- return s;
- }
- function deepTranslate(obj) {
- if (typeof obj === 'string') return translateString(obj);
- if (Array.isArray(obj)) return obj.map(deepTranslate);
- if (obj && typeof obj === 'object') {
- const out = {};
- for (const [k, v] of Object.entries(obj)) out[k] = deepTranslate(v);
- return out;
- }
- return obj;
- }
- function overlayByKey(zhPart, enPart, refPart) {
- if (!zhPart || !enPart || !refPart) return;
- for (const key of Object.keys(zhPart)) {
- if (refPart[key] === undefined) continue;
- if (typeof zhPart[key] === 'string' && typeof refPart[key] === 'string') {
- enPart[key] = refPart[key];
- } else if (typeof zhPart[key] === 'object' && zhPart[key] !== null && !Array.isArray(zhPart[key])) {
- if (!enPart[key] || typeof enPart[key] !== 'object') enPart[key] = {};
- overlayByKey(zhPart[key], enPart[key], refPart[key]);
- }
- }
- }
- const en = deepTranslate(JSON.parse(JSON.stringify(zh)));
- for (const key of Object.keys(zh)) {
- if (typeof zh[key] === 'object' && oldPcEn[key]) {
- overlayByKey(zh[key], en[key], oldPcEn[key]);
- }
- }
- if (oldPcEn.manage && zh.scene) {
- overlayByKey(zh.scene, en.scene, {
- sceneAdmin: oldPcEn.manage.sceneAdmin,
- myScenes: oldPcEn.manage.sceneAdmin,
- sceneDownload: oldPcEn.manage.sceneDownload,
- });
- }
- if (oldPcEn.manage && zh.deviceAdmin) {
- overlayByKey(zh.deviceAdmin, en.deviceAdmin, oldPcEn.manage.deviceAdmin || {});
- }
- if (oldPcEn.manage && zh.member) {
- overlayByKey(zh.member, en.member, oldPcEn.manage.member || oldPcEn.member || {});
- }
- if (en.login && en.login.agreeXieyi) {
- en.toast = en.toast || {};
- en.toast.agreeXieyi = en.login.agreeXieyi;
- }
- fs.writeFileSync(enPath, `${JSON.stringify(en, null, 2)}\n`);
- const untranslated = [];
- function countUntranslated(zhPart, enPart, path = '') {
- if (typeof zhPart === 'string' && typeof enPart === 'string') {
- if (zhPart === enPart && /[\u4e00-\u9fff]/.test(zhPart)) {
- untranslated.push(path);
- }
- return;
- }
- if (zhPart && enPart && typeof zhPart === 'object' && !Array.isArray(zhPart)) {
- for (const key of Object.keys(zhPart)) {
- countUntranslated(zhPart[key], enPart[key], path ? `${path}.${key}` : key);
- }
- }
- }
- countUntranslated(zh, en);
- console.log(`en.json generated. Untranslated strings: ${untranslated.length}`);
- if (untranslated.length > 0 && untranslated.length <= 20) {
- console.log(untranslated.join('\n'));
- }
|