mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-06-30 10:44:50 +02:00
parent
ceb694da74
commit
5c3191d424
|
@ -55,15 +55,15 @@ Just `import`/`require` your locale `.json` files and pass them to the [`addMess
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// src/i18n.js
|
// src/i18n.js
|
||||||
import { addMessages } from 'svelte-i18n'
|
import { addMessages } from 'svelte-i18n';
|
||||||
|
|
||||||
import en from './en.json'
|
import en from './en.json';
|
||||||
import enUS from './en-US.json'
|
import enUS from './en-US.json';
|
||||||
import pt from './pt.json'
|
import pt from './pt.json';
|
||||||
|
|
||||||
addMessages('en', en)
|
addMessages('en', en);
|
||||||
addMessages('en-US', enUS)
|
addMessages('en-US', enUS);
|
||||||
addMessages('pt', pt)
|
addMessages('pt', pt);
|
||||||
|
|
||||||
// en, en-US and pt are available
|
// en, en-US and pt are available
|
||||||
```
|
```
|
||||||
|
@ -74,11 +74,11 @@ A more performant way to load your dictionaries is to register `loader` methods.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// src/i18n.js
|
// src/i18n.js
|
||||||
import { register } from 'svelte-i18n'
|
import { register } from 'svelte-i18n';
|
||||||
|
|
||||||
register('en', () => import('./en.json'))
|
register('en', () => import('./en.json'));
|
||||||
register('en-US', () => import('./en-US.json'))
|
register('en-US', () => import('./en-US.json'));
|
||||||
register('pt', () => import('./pt.json'))
|
register('pt', () => import('./pt.json'));
|
||||||
|
|
||||||
// en, en-US and pt are not available yet
|
// en, en-US and pt are not available yet
|
||||||
```
|
```
|
||||||
|
@ -89,21 +89,21 @@ After populating your [`$dictionary`](/docs/Dictionary.md) with [`addMessages()`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// src/i18n.js
|
// src/i18n.js
|
||||||
import { register, init, getLocaleFromNavigator } from 'svelte-i18n'
|
import { register, init, getLocaleFromNavigator } from 'svelte-i18n';
|
||||||
|
|
||||||
register('en', () => import('./en.json'))
|
register('en', () => import('./en.json'));
|
||||||
register('en-US', () => import('./en-US.json'))
|
register('en-US', () => import('./en-US.json'));
|
||||||
register('pt', () => import('./pt.json'))
|
register('pt', () => import('./pt.json'));
|
||||||
// en, en-US and pt are not available yet
|
// en, en-US and pt are not available yet
|
||||||
|
|
||||||
init({
|
init({
|
||||||
fallbackLocale: 'en',
|
fallbackLocale: 'en',
|
||||||
initialLocale: getLocaleFromNavigator(),
|
initialLocale: getLocaleFromNavigator(),
|
||||||
})
|
});
|
||||||
// starts loading 'en-US' and 'en'
|
// starts loading 'en-US' and 'en'
|
||||||
```
|
```
|
||||||
|
|
||||||
_**Note**: If you're using Sapper, remember to also call `init()` on your server side code (`server.js`)._
|
_Note_: Make sure to call your `i18n.js` file on your app's entrypoint. If you're using Sapper, remember to also call `init()` on your server-side code (`server.js`).
|
||||||
|
|
||||||
Since we're using `register`, and not `addMessages`, we need to wait for it's loaders to finish before rendering your app.
|
Since we're using `register`, and not `addMessages`, we need to wait for it's loaders to finish before rendering your app.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user