mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-06-30 18:54:49 +02:00
chore: 🤖 testing partial loading and merging
This commit is contained in:
parent
31faccec3b
commit
5ada5beed3
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"printWidth": 100,
|
"printWidth": 100,
|
||||||
"trailingComma": "all",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false,
|
"jsxBracketSameLine": false,
|
||||||
"singleQuote": true
|
"singleQuote": true
|
||||||
|
|
10
example/messages/en.json
Normal file
10
example/messages/en.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"title": {
|
||||||
|
"index": "Sapper project template!"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"success": "Great success!",
|
||||||
|
"high_five": "High five",
|
||||||
|
"try_editing": "Try editing this file (src/routes/index.svelte) to test live reloading."
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
import { dictionary } from 'svelte-i18n'
|
import { registerLocaleLoader } from 'svelte-i18n'
|
||||||
|
|
||||||
dictionary.set({
|
registerLocaleLoader('en', () => import('../messages/en.json'))
|
||||||
'pt-BR': () => import('../messages/pt-BR.json'),
|
registerLocaleLoader('pt-BR', () => import('../messages/pt-BR.json'))
|
||||||
'en-US': () => import('../messages/en-US.json'),
|
registerLocaleLoader('en-US', () => import('../messages/en-US.json'))
|
||||||
'es-ES': () => import('../messages/es-ES.json'),
|
registerLocaleLoader('es-ES', () => import('../messages/es-ES.json'))
|
||||||
})
|
|
||||||
|
|
|
@ -30,16 +30,16 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<Lang let:loading>
|
<Lang let:loading>{loading}</Lang>
|
||||||
{loading}
|
|
||||||
</Lang>
|
|
||||||
|
|
||||||
<Nav {segment} />
|
<Nav {segment} />
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<select bind:value={$locale}>
|
<select bind:value={$locale}>
|
||||||
{#each $locales as locale}
|
{#each $locales as locale}
|
||||||
<option value={locale}>{localeLabels[locale]}</option>
|
{#if locale in localeLabels}
|
||||||
|
<option value={locale}>{localeLabels[locale]}</option>
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<script context="module">
|
<script context="module">
|
||||||
// import { partial } from 'svelte-i18n'
|
import { registerLocaleLoader, flushLocaleQueue } from 'svelte-i18n'
|
||||||
|
|
||||||
|
registerLocaleLoader('en-US', () => import('./_locales/en-US.json'))
|
||||||
|
registerLocaleLoader('pt-BR', () => import('./_locales/pt-BR.json'))
|
||||||
|
registerLocaleLoader('es-ES', () => import('./_locales/es-ES.json'))
|
||||||
|
|
||||||
export async function preload() {
|
export async function preload() {
|
||||||
// return partial({
|
return flushLocaleQueue()
|
||||||
// 'en-US': () => import('./_locales/en-US.json'),
|
|
||||||
// 'pt-BR': () => import('./_locales/pt-BR.json'),
|
|
||||||
// 'es-ES': () => import('./_locales/es-ES.json'),
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -20,8 +20,4 @@
|
||||||
|
|
||||||
<h1>{$_('about_this_site', { default: 'About this site' })}</h1>
|
<h1>{$_('about_this_site', { default: 'About this site' })}</h1>
|
||||||
|
|
||||||
<p>
|
<p>{$_('about_content[0]', { default: "This is the 'about' page. There's not much here." })}</p>
|
||||||
{$_('about_content[0]', {
|
|
||||||
default: "This is the 'about' page. There's not much here.",
|
|
||||||
})}
|
|
||||||
</p>
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import {
|
||||||
addCustomFormats,
|
addCustomFormats,
|
||||||
customFormats,
|
customFormats,
|
||||||
preloadLocale,
|
preloadLocale,
|
||||||
|
registerLocaleLoader,
|
||||||
|
flushLocaleQueue,
|
||||||
} from '../../src/client'
|
} from '../../src/client'
|
||||||
|
|
||||||
global.Intl = require('intl')
|
global.Intl = require('intl')
|
||||||
|
@ -16,12 +18,13 @@ let currentLocale: string
|
||||||
|
|
||||||
const dict = {
|
const dict = {
|
||||||
en: require('../fixtures/en.json'),
|
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 => {
|
format.subscribe(formatFn => {
|
||||||
_ = formatFn
|
_ = formatFn
|
||||||
})
|
})
|
||||||
|
@ -29,7 +32,6 @@ dictionary.set(dict)
|
||||||
locale.subscribe((l: string) => {
|
locale.subscribe((l: string) => {
|
||||||
currentLocale = l
|
currentLocale = l
|
||||||
})
|
})
|
||||||
locale.set('en')
|
|
||||||
|
|
||||||
describe('locale', () => {
|
describe('locale', () => {
|
||||||
it('should change locale', () => {
|
it('should change locale', () => {
|
||||||
|
@ -61,6 +63,15 @@ describe('dictionary', () => {
|
||||||
expect(loaded[0][0]).toEqual('pt')
|
expect(loaded[0][0]).toEqual('pt')
|
||||||
expect(loaded[1][0]).toEqual('pt-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', () => {
|
describe('formatting', () => {
|
||||||
|
@ -219,7 +230,6 @@ describe('custom formats', () => {
|
||||||
locale.set('en-US')
|
locale.set('en-US')
|
||||||
|
|
||||||
expect(_.number(123123123, { format: 'usd' })).toContain('$123,123,123.00')
|
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')
|
expect(_.date(new Date(2019, 0, 1), { format: 'customDate' })).toEqual('2019 AD')
|
||||||
|
|
||||||
|
|
3
test/fixtures/en.json
vendored
3
test/fixtures/en.json
vendored
|
@ -1,6 +1,9 @@
|
||||||
{
|
{
|
||||||
"hi": "hi yo",
|
"hi": "hi yo",
|
||||||
"switch.lang": "Switch language",
|
"switch.lang": "Switch language",
|
||||||
|
"page": {
|
||||||
|
"title_home": "Home"
|
||||||
|
},
|
||||||
"greeting": {
|
"greeting": {
|
||||||
"ask": "Please type your name",
|
"ask": "Please type your name",
|
||||||
"message": "Hello {name}, how are you?"
|
"message": "Hello {name}, how are you?"
|
||||||
|
|
5
test/fixtures/partials/en.json
vendored
Normal file
5
test/fixtures/partials/en.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"page": {
|
||||||
|
"title_about": "About"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1623,6 +1623,11 @@ deep-is@~0.1.3:
|
||||||
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
|
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
|
||||||
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
|
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:
|
define-properties@^1.1.2, define-properties@^1.1.3:
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
|
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user