Skip to main content
Version: 4.x.x

Switching language

When developing multi-language app, you will need to provide a language switcher to your app. To switch the language, use getLanguageStore method which returns writeable store containing current language tag.

<script lang="ts">
import { getLanguageStore } from "@tolgee/svelte";

const languageStore = getLanguageStore();
</script>

<select bind:value={$languageStore} class="lang-selector">
<option value="en">🇬🇧 English</option>
<option value="de">🇩🇪 Deutsch</option>
</select>

Forcing Tolgee to use specific language

By default, Tolgee tries to set the language according to user's system language. Sometimes you need to force it to use specific language. For example when you are working with SSR or your language is determined by a route.

To do so, use forceLanguage property of TolgeeProvider's config prop.

<script lang="ts">
import { TolgeeProvider } from "@tolgee/svelte";
import type { TolgeeConfig } from "@tolgee/core";

const tolgeeConfig = {
...
forceLanguage='de' // !!! HERE
} as TolgeeConfig;
</script>

<TolgeeProvider config={tolgeeConfig}>
...
</TolgeeProvider>

To read more about Tolgee configuration see configuration doc page.