Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(i18n): keep overrides for equivalent-case locale tags in the Viewer catalog

uygnoey33e80c5964d6
diff --git a/archify.zip b/archify.zip
index 83926e59..90ef8319 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/shared/i18n.mjs b/archify/renderers/shared/i18n.mjs
index b0720a56..6eee0b50 100644
--- a/archify/renderers/shared/i18n.mjs
+++ b/archify/renderers/shared/i18n.mjs
@@ -195,13 +195,19 @@ export function resolveCatalog(locale, translations = undefined) {
};
}
-// Per-document catalogs installed by registerLocale(), keyed by the authored
-// tag so renderers can keep passing meta.locale. They never mutate a bundled
-// catalog.
+// Per-document catalogs installed by registerLocale(). Tags are
+// case-insensitive, so the key is lowercased: renderers may pass the authored
+// meta.locale (zh-cn) or its resolved tag (zh-CN) and reach the same document
+// catalog. They never mutate a bundled catalog.
const DOCUMENT_CATALOGS = new Map();
+function documentKey(locale) {
+ return typeof locale === 'string' ? locale.toLowerCase() : locale;
+}
+
function catalogFor(locale) {
- if (DOCUMENT_CATALOGS.has(locale)) return DOCUMENT_CATALOGS.get(locale);
+ const key = documentKey(locale);
+ if (DOCUMENT_CATALOGS.has(key)) return DOCUMENT_CATALOGS.get(key);
const bundledLocale = bundledLocaleFor(locale);
return bundledLocale ? { locale: bundledLocale, messages: bundledCatalog(bundledLocale).messages } : null;
}
@@ -212,9 +218,9 @@ function catalogFor(locale) {
export function registerLocale(locale, translations = undefined) {
const { messages, report } = resolveCatalog(locale, translations);
if (report.fallback || !locale) {
- DOCUMENT_CATALOGS.delete(locale);
+ DOCUMENT_CATALOGS.delete(documentKey(locale));
} else {
- DOCUMENT_CATALOGS.set(locale, { locale: report.resolvedLocale, messages });
+ DOCUMENT_CATALOGS.set(documentKey(locale), { locale: report.resolvedLocale, messages });
}
return report;
}
diff --git a/archify/test/i18n.test.mjs b/archify/test/i18n.test.mjs
index af467867..839996b2 100644
--- a/archify/test/i18n.test.mjs
+++ b/archify/test/i18n.test.mjs
@@ -603,6 +603,22 @@ test('empty translations and equivalent tag casing select the same bundled catal
assert.equal(empty.stderr, '');
assert.equal(empty.html, korean.html, `${type}: {} is not an override`);
}
+ // An override under an equivalent-case tag reaches every lookup path: SVG
+ // copy, the HTML template, and the embedded Viewer catalog.
+ for (const locale of ['zh-cn', 'zh-cN']) {
+ for (const type of Object.keys(EXAMPLES)) {
+ const result = run(type, localeDocument(type, {
+ locale,
+ translations: { 'viewer.common.close': '关闭面板', 'viewer.export.diagram': '导出此图' },
+ }));
+ assert.equal(result.status, 0, result.stderr);
+ assert.match(result.html, /^<!DOCTYPE html>\n<html lang="zh-CN"/);
+ const runtime = embeddedMessages(result.html);
+ assert.equal(runtime.locale, 'zh-CN');
+ assert.equal(runtime.messages['viewer.common.close'], '关闭面板', `${type}/${locale}: embedded Viewer override lost`);
+ assert.ok(result.html.includes('>导出此图<'), `${type}/${locale}: template override lost`);
+ }
+ }
assert.equal(bundledLocaleFor('ZH-cn'), 'zh-CN');
assert.equal(bundledLocaleFor('zh-Hant'), null);
assert.equal(bundledLocaleFor('zh'), null);