feat(i18n): ③ 底座 — serve.mjs 暴露 canonical strings.json 给原型
原型与 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo
This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user