Skip to main content
Version: 5.x.x

Installation (Svelte)

Check our Svelte example application

To install Tolgee Svelte integration library, run:

npm install @tolgee/svelte

Init Tolgee and wrap your application in TolgeeProvider.

<script>
import { TolgeeProvider, Tolgee, DevTools, FormatSimple } from '@tolgee/svelte';

const tolgee = Tolgee()
.use(DevTools())
.use(FormatSimple())
.init({
language: 'en',

// for development
apiUrl: import.meta.env.VITE_TOLGEE_API_URL,
apiKey: import.meta.env.VITE_TOLGEE_API_KEY,

// for production
staticData: {
...
}
});
</script>

<TolgeeProvider tolgee={tolgee}>
<div slot="fallback">Loading...</div>
<slot />
</TolgeeProvider>

Check all tolgee options and tolgee plugins.

If you bootstrapped your application with SvelteKit, your .env.development.local file should look like this:

VITE_TOLGEE_API_KEY=tgpak_gfpwiojtnrztqmtbna3dczjxny2ha3dmnu4tk4tnnjvgc
VITE_TOLGEE_API_URL=https://app.tolgee.io
danger

Never leak your API key! You don't want visitors of your site to edit your translations. That's why we recommend to use .env files to store your API key. API key is then omitted for production build.

Obtaining Tolgee API key is described in Integration chapter.

Preparing for production

Tolgee will automatically omit DevTools from your bundle when you build your app for production. So it won't fetch translations directly from Tolgee Platform and it won't allow users to modify translations.

There are generally two ways how to use translations in production:

In production mode, you should never use localization data directly from Tolgee REST API, because it can negatively affect your page performance.