feat: add i18n system with English locale
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createI18n } from '$lib/i18n';
|
||||
|
||||
describe('i18n', () => {
|
||||
const i18n = createI18n({
|
||||
'common.save': 'Save',
|
||||
'common.cancel': 'Cancel',
|
||||
'pets.title': 'Our Pets',
|
||||
'pets.count': '{count} pets available',
|
||||
'greeting': 'Hello, {name}!'
|
||||
});
|
||||
|
||||
it('returns translated string by key', () => {
|
||||
expect(i18n.t('common.save')).toBe('Save');
|
||||
expect(i18n.t('pets.title')).toBe('Our Pets');
|
||||
});
|
||||
|
||||
it('returns key when translation is missing', () => {
|
||||
expect(i18n.t('missing.key')).toBe('missing.key');
|
||||
});
|
||||
|
||||
it('interpolates variables', () => {
|
||||
expect(i18n.t('greeting', { name: 'Justin' })).toBe('Hello, Justin!');
|
||||
expect(i18n.t('pets.count', { count: '5' })).toBe('5 pets available');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user