Installation:
npm install svelte-i18n-light
translations.json
{
"en": {
"hello": "hello world"
},
"de": {
"hello": "hallo Welt"
}
import { dict, locale, t } from "svelte-i18n-light";
import translations from "translations";
$: languages = Object.keys(translations);
$: dict.set(translations);
....
function selectLang(e) {
let langElem = e.target;
$locale = langElem.innerHTML;
handleMenuOpen();
}
....
{#each languages as lang}
<li
on:click={selectLang}
>
<p class:font-bold={$locale == lang}>
{lang}
</p>
</li>
{/each}
<script>
import { t } from 'svelte-i18n-light'
</script>
{$t('hello')}