diff --git a/packages/runtime/tests/i18n.test.ts b/packages/runtime/tests/i18n.test.ts new file mode 100644 index 0000000..d735b9e --- /dev/null +++ b/packages/runtime/tests/i18n.test.ts @@ -0,0 +1,224 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync, readdirSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { + argumentShapes, createI18n, direction, fallbackChain, formatMessage, matchLocale, normalizeLocale, + parseMessage, placeholders, pluralCategories, relativeParts, type Catalog, +} from '../src/i18n.ts'; +import { checkCatalog, checkMessageSafety, checkShape, checkSource, coverage, generateKeyTypes, type CatalogIssue } from '../src/i18nCheck.ts'; +import { createPluginI18n, pluginNamespace } from '../src/pluginI18n.ts'; +import { KIT_MESSAGES } from '../src/ui.ts'; +import { SHELL_MESSAGES, shellText } from '../../shell/src/messages.ts'; + +const here = dirname(fileURLToPath(import.meta.url)); + +test('locale tags are normalized, including X and legacy codes', () => { + assert.equal(normalizeLocale('en_gb'), 'en-GB'); + assert.equal(normalizeLocale('zh-cn'), 'zh-Hans'); + assert.equal(normalizeLocale('zh-TW'), 'zh-Hant'); + assert.equal(normalizeLocale('zh-Hant-HK'), 'zh-Hant'); + assert.equal(normalizeLocale('zh'), 'zh-Hans'); + assert.equal(normalizeLocale('msa'), 'ms'); + assert.equal(normalizeLocale('no'), 'nb'); + assert.equal(normalizeLocale('iw'), 'he'); + assert.equal(normalizeLocale('ar-x-fm'), 'ar-x-fm'); + assert.equal(normalizeLocale('pt-br'), 'pt-BR'); + for (const bad of ['', 'x', 'english!', '