From f46191ef4dc37d350680bdd3f5f780682851e5ee Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 27 Jul 2026 08:57:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20=E2=91=A2=20=E5=BA=95=E5=BA=A7=20?= =?UTF-8?q?=E2=80=94=20serve.mjs=20=E6=9A=B4=E9=9C=B2=20canonical=20string?= =?UTF-8?q?s.json=20=E7=BB=99=E5=8E=9F=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原型与 Flutter app 共用同一份 design/i18n/strings.json(不在原型内复制): - serve.mjs 加路由 /i18n/strings.json(及别名 /strings.json)→ 直读 ../i18n/strings.json。 - 原型 JS 可 fetch 同源翻译;完整 data-i18n key remap(3 套 key 空间对齐)为后续工作。 Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo --- design/prototype/serve.mjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/design/prototype/serve.mjs b/design/prototype/serve.mjs index 811eaf4..3d3ad9c 100644 --- a/design/prototype/serve.mjs +++ b/design/prototype/serve.mjs @@ -47,6 +47,19 @@ const server = http.createServer((req, res) => { let urlPath = decodeURIComponent(req.url.split('?')[0]); if (urlPath === '/') urlPath = '/index.html'; + + // i18n 单源:直接服务 canonical design/i18n/strings.json(不在原型内复制)。 + // 原型与 Flutter app 共用同一份翻译数据(design/codegen/gen_l10n_dart.mjs 由它生成 Dart)。 + if (urlPath === '/i18n/strings.json' || urlPath === '/strings.json') { + const sjPath = path.join(ROOT, '..', 'i18n', 'strings.json'); + fs.readFile(sjPath, (err, data) => { + if (err) { res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end('strings.json not found'); return; } + res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' }); + res.end(data); + }); + return; + } + const filePath = path.join(ROOT, urlPath); if (!filePath.startsWith(ROOT)) { res.writeHead(403); res.end('forbidden'); return; }