{$_('about_this_site', { default: 'About this site' })}
-- {$_('about_content[0]', { - default: "This is the 'about' page. There's not much here.", - })} -
+{$_('about_content[0]', { default: "This is the 'about' page. There's not much here." })}
diff --git a/test/client/index.test.ts b/test/client/index.test.ts index da89a17..cbbec40 100644 --- a/test/client/index.test.ts +++ b/test/client/index.test.ts @@ -7,6 +7,8 @@ import { addCustomFormats, customFormats, preloadLocale, + registerLocaleLoader, + flushLocaleQueue, } from '../../src/client' global.Intl = require('intl') @@ -16,12 +18,13 @@ let currentLocale: string const dict = { en: require('../fixtures/en.json'), - 'en-GB': () => import('../fixtures/en-GB.json'), - pt: () => import('../fixtures/pt.json'), - 'pt-BR': () => import('../fixtures/pt-BR.json'), - 'pt-PT': () => import('../fixtures/pt-PT.json'), } +registerLocaleLoader('en-GB', () => import('../fixtures/en-GB.json')) +registerLocaleLoader('pt', () => import('../fixtures/pt.json')) +registerLocaleLoader('pt-BR', () => import('../fixtures/pt-BR.json')) +registerLocaleLoader('pt-PT', () => import('../fixtures/pt-PT.json')) + format.subscribe(formatFn => { _ = formatFn }) @@ -29,7 +32,6 @@ dictionary.set(dict) locale.subscribe((l: string) => { currentLocale = l }) -locale.set('en') describe('locale', () => { it('should change locale', () => { @@ -61,6 +63,15 @@ describe('dictionary', () => { expect(loaded[0][0]).toEqual('pt') expect(loaded[1][0]).toEqual('pt-PT') }) + + it('load a partial dictionary and merge it with the existing one', async () => { + locale.set('en') + registerLocaleLoader('en', () => import('../fixtures/partials/en.json')) + expect(_('page.title_about')).toBe('page.title_about') + + await flushLocaleQueue('en') + expect(_('page.title_about')).toBe('About') + }) }) describe('formatting', () => { @@ -219,7 +230,6 @@ describe('custom formats', () => { locale.set('en-US') expect(_.number(123123123, { format: 'usd' })).toContain('$123,123,123.00') - expect(_.number(123123123, { format: 'brl' })).toContain('R$123,123,123.00') expect(_.date(new Date(2019, 0, 1), { format: 'customDate' })).toEqual('2019 AD') diff --git a/test/fixtures/en.json b/test/fixtures/en.json index e5a3898..432f9d7 100644 --- a/test/fixtures/en.json +++ b/test/fixtures/en.json @@ -1,6 +1,9 @@ { "hi": "hi yo", "switch.lang": "Switch language", + "page": { + "title_home": "Home" + }, "greeting": { "ask": "Please type your name", "message": "Hello {name}, how are you?" diff --git a/test/fixtures/partials/en.json b/test/fixtures/partials/en.json new file mode 100644 index 0000000..8dc22dd --- /dev/null +++ b/test/fixtures/partials/en.json @@ -0,0 +1,5 @@ +{ + "page": { + "title_about": "About" + } +} diff --git a/yarn.lock b/yarn.lock index f896c2f..779fad2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1623,6 +1623,11 @@ deep-is@~0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= +deepmerge@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" + integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== + define-properties@^1.1.2, define-properties@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"