svelte-i18next

Svelte wrapper for i18next

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
svelte-i18next
1541.2.26 months ago6 months agoMinified + gzip package size for svelte-i18next in KB

Readme

svelte-i18next Tweet
CI npm version bundle size License
Svelte wrapper for i18next
npm i svelte-i18next i18next

Implementation

This library wraps an i18next instance in a Svelte Store to observe i18next events so your Svelte components re-render e.g. when language is changed or a new resource is loaded by i18next.

Quick Start

i18n.js:
import i18next from "i18next";
import { createI18nStore } from "svelte-i18next";

i18next.init({
 lng: 'en',
 resources: {
    en: {
      translation: {
        "key": "hello world"
      }
    }
  },
  interpolation: {
    escapeValue: false, // not needed for svelte as it escapes by default
  }
});

export const i18n = createI18nStore(i18next);

App.svelte:
<script>
  import i18n from './i18n.js';
</script>

<div>
    {$i18n.t('key')}}
</div>

See full example project: Svelte example