Tolgee for Svelte provides a simple API to create multi-lingual Svelte application. With Tolgee i18n library for Svelte, you can enjoy all Tolgee i18n features.
To see Svelte with Tolgee in action, check this example app.
npm i @tolgee/svelte
Get started!
1. Create project in Tolgee platform
Go to Tolgee Cloud app or access your self-hosted instance and create a project. Then obtain your API key.
2. Setup Tolgee integration
Install the npm package:
npm i @tolgee/svelte
Then initialize Tolgee and wrap your code with TolgeeProvider
<script>
import { TolgeeProvider, Tolgee, DevTools, FormatSimple } from '@tolgee/svelte';
const tolgee = Tolgee()
.use(DevTools())
.use(FormatSimple())
.init({
language: 'en',
apiUrl: import.meta.env.VITE_TOLGEE_API_URL,
apiKey: import.meta.env.VITE_TOLGEE_API_KEY,
});
</script>
<TolgeeProvider tolgee={tolgee}>
<div slot="fallback">Loading...</div>
<slot />
</TolgeeProvider>
3. Use T component to translate your texts
<script>
import { T } from "@tolgee/svelte";
</script>
<h1>
<T keyName="translate_me" defaultValue="Translate me!" />
</h1>
Now you are able to Alt + Click & translate your texts!