Internationalization library for Svelte
Go to file
2018-08-09 15:53:54 -03:00
src Handle nonexistent locale switch 2018-08-09 15:53:54 -03:00
test Handle nonexistent locale switch 2018-08-09 15:53:54 -03:00
.babelrc Namespace i18n store methods with "i18n" property 2018-08-08 20:17:08 -03:00
.editorconfig I'm sorry Typescript, it's not you... 2018-08-07 18:53:07 -03:00
.eslintignore I'm sorry Typescript, it's not you... 2018-08-07 18:53:07 -03:00
.eslintrc I'm sorry Typescript, it's not you... 2018-08-07 18:53:07 -03:00
.gitignore Make tests work again. New utility structure 2018-08-08 02:17:09 -03:00
.npmignore Ignore coverage folder 2018-08-08 20:17:49 -03:00
.prettierrc I'm sorry Typescript, it's not you... 2018-08-07 18:53:07 -03:00
LICENSE 👶 Initial commit 2018-07-25 22:50:55 -03:00
package-lock.json Namespace i18n store methods with "i18n" property 2018-08-08 20:17:08 -03:00
package.json Handle nonexistent locale switch 2018-08-09 15:53:54 -03:00
README.md Namespace i18n store methods with "i18n" property 2018-08-08 20:17:08 -03:00

svelte-i18n

Internationalization for svelte

Work-in-progress

Usage

On the store

import i18n from 'svelte-i18n'
import { Store } from 'svelte/store'

/** i18n(svelteStore, { dictionary }) */
const store = i18n(new Store(), {
  dictionary: {
    'pt-BR': {
      message: 'Mensagem',
      messages: {
        alert: 'Alerta',
        error: 'Erro',
      },
    },
    'en-US': {
      message: 'Message',
      messages: {
        alert: 'Alert',
        error: 'Error',
      },
    },
  },
})

/**
 * Extend the initial dictionary.
 * Dictionaries are deeply merged.
 * */
store.i18n.extendDictionary({
  'pt-BR': {
    messages: {
      warn: 'Aviso',
      success: 'Sucesso',
    },
  },
  'en-US': {
    messages: {
      warn: 'Warn',
      success: 'Success',
    },
  },
})

/** Set the initial locale */
store.i18n.setLocale('en-US')

On templates

<div>
  {$_('message')}: {$_.upper('messages.success'))}
</div>

Renders:

Message: SUCCESS