feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
80
packages/i18n/__tests__/locale-contract.test.ts
Normal file
80
packages/i18n/__tests__/locale-contract.test.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { LOCALE_CODES, LOCALE_META, isValidLocale, resolveTranslationWithFallback, toBcp47 } from '../src/shared'
|
||||
|
||||
const LOCALES_DIR = path.resolve(__dirname, '../src/locales')
|
||||
|
||||
function extractPlaceholders(value: string): string[] {
|
||||
const matches = [...value.matchAll(/\{\{([a-zA-Z0-9_]+)\}\}/g)]
|
||||
return [...new Set(matches.map((m) => m[1]))].sort()
|
||||
}
|
||||
|
||||
describe('@d3ro/i18n 12개 로케일 계약 테스트 (G5 / GAP-I18N-03)', () => {
|
||||
const ko = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'ko.json'), 'utf8')) as Record<string, string>
|
||||
const en = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'en.json'), 'utf8')) as Record<string, string>
|
||||
const masterKeys = Object.keys(ko)
|
||||
|
||||
it('LOCALE_META_12개지원언어코드와순서가LOCALE_CODES와일치한다', () => {
|
||||
expect(LOCALE_CODES).toHaveLength(12)
|
||||
expect(LOCALE_META.map((item) => item.code)).toEqual([...LOCALE_CODES])
|
||||
for (const code of LOCALE_CODES) {
|
||||
expect(isValidLocale(code)).toBe(true)
|
||||
}
|
||||
expect(isValidLocale('invalid-locale')).toBe(false)
|
||||
})
|
||||
|
||||
it.each(LOCALE_CODES)(
|
||||
'로케일사전_%s_마스터키집합과동일하고빈문자열이없다',
|
||||
(localeCode) => {
|
||||
const catalog = JSON.parse(
|
||||
fs.readFileSync(path.join(LOCALES_DIR, `${localeCode}.json`), 'utf8'),
|
||||
) as Record<string, string>
|
||||
const keys = Object.keys(catalog)
|
||||
const missing = masterKeys.filter((k) => !(k in catalog))
|
||||
const extra = keys.filter((k) => !(k in ko))
|
||||
const empty = masterKeys.filter((k) => typeof catalog[k] !== 'string' || catalog[k].trim().length === 0)
|
||||
|
||||
expect(missing).toEqual([])
|
||||
expect(extra).toEqual([])
|
||||
expect(empty).toEqual([])
|
||||
},
|
||||
)
|
||||
|
||||
it('플레이스홀더정합성_영어번역의치환변수목록이한국어마스터와일치한다', () => {
|
||||
const mismatches: string[] = []
|
||||
for (const key of masterKeys) {
|
||||
const koTokens = extractPlaceholders(ko[key] ?? '')
|
||||
const enTokens = extractPlaceholders(en[key] ?? '')
|
||||
if (koTokens.join(',') !== enTokens.join(',')) {
|
||||
mismatches.push(`${key}: ko=[${koTokens.join(',')}] vs en=[${enTokens.join(',')}]`)
|
||||
}
|
||||
}
|
||||
expect(mismatches).toEqual([])
|
||||
})
|
||||
|
||||
it('resolveTranslationWithFallback_누락키발생시_영어한국어키순으로안전하게폴백한다', () => {
|
||||
expect(
|
||||
resolveTranslationWithFallback(
|
||||
'greeting',
|
||||
{ greeting: 'こんにちは {{name}}' },
|
||||
{ greeting: 'Hello {{name}}' },
|
||||
{ greeting: '안녕 {{name}}' },
|
||||
{ name: 'D3RO' },
|
||||
),
|
||||
).toBe('こんにちは D3RO')
|
||||
|
||||
expect(
|
||||
resolveTranslationWithFallback(
|
||||
'missing.in.primary',
|
||||
{},
|
||||
{ 'missing.in.primary': 'Fallback EN' },
|
||||
{ 'missing.in.primary': '폴백 KO' },
|
||||
),
|
||||
).toBe('Fallback EN')
|
||||
|
||||
expect(toBcp47('zh')).toBe('zh-CN')
|
||||
expect(toBcp47('zh-TW')).toBe('zh-TW')
|
||||
expect(toBcp47('ko')).toBe('ko')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue