2018-07-26 06:40:19 +02:00
|
|
|
# svelte-i18n
|
2018-07-26 03:40:38 +02:00
|
|
|
|
2018-07-26 06:40:19 +02:00
|
|
|
> Internationalization for svelte
|
2018-07-26 03:40:38 +02:00
|
|
|
|
2018-07-27 04:24:17 +02:00
|
|
|
**Work-in-progress**
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
### On the `store`
|
|
|
|
|
|
|
|
```js
|
|
|
|
import i18n from 'svelte-i18n'
|
|
|
|
import { Store } from 'svelte/store'
|
|
|
|
|
|
|
|
const store = new Store()
|
|
|
|
|
|
|
|
/** i18n(svelteStore, arrayOfLocalesObjects) */
|
|
|
|
i18n(store, [
|
|
|
|
{
|
|
|
|
'pt-BR': {
|
|
|
|
message: 'Mensagem',
|
|
|
|
messages: {
|
|
|
|
alert: 'Alerta',
|
|
|
|
error: 'Erro'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'en-US': {
|
|
|
|
message: 'Message',
|
|
|
|
messages: {
|
|
|
|
alert: 'Alert',
|
|
|
|
error: 'Error'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/** Locales are deeply merged */
|
|
|
|
{
|
|
|
|
'pt-BR': {
|
|
|
|
messages: {
|
|
|
|
warn: 'Aviso',
|
|
|
|
success: 'Sucesso'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'en-US': {
|
|
|
|
messages: {
|
|
|
|
warn: 'Warn',
|
|
|
|
success: 'Success'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
```
|
|
|
|
|
|
|
|
### On `templates`
|
|
|
|
|
|
|
|
```html
|
|
|
|
<div>
|
|
|
|
{$_('message')}: {$_.upper('messages.success')}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Will render for en-US -->
|
|
|
|
Message: SUCCESS
|
|
|
|
```
|