Files
landing-builder/lib/i18n/i18n.test.ts
T

26 lines
789 B
TypeScript

import { describe, it, expect } from 'vitest'
import { createI18n } from '@/lib/i18n'
describe('i18n util', () => {
const i18n = createI18n({
defaultLocale: 'en',
messages: {
en: { hello: 'Hello {name}', onlyEn: 'Only EN' },
ko: { hello: '안녕하세요 {name}' },
},
})
it('로케일별 번역과 변수 치환을 지원한다', () => {
expect(i18n.t('en', 'hello', { name: 'Jay' })).toBe('Hello Jay')
expect(i18n.t('ko', 'hello', { name: '제이' })).toBe('안녕하세요 제이')
})
it('키가 없으면 기본 로케일로 폴백한다', () => {
expect(i18n.t('ko', 'onlyEn')).toBe('Only EN')
})
it('완전히 없는 키는 키 그대로 반환한다', () => {
expect(i18n.t('en', 'missing.key')).toBe('missing.key')
})
})