Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Init history"v9.8.511/23/2026
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Migrating from svelte-i18n to Intlayer
Why migrate from svelte-i18n to Intlayer?
svelte-i18n registers whole locale files at startup. Intlayer only ships the dictionaries each page uses, which reduces your bundle and page sizes by up to 50%.
Keys are typed against your dictionaries: invalid keys fail at build time. Content can be co-located with the components that use it.
Co-located content reduces the context needed by LLMs. Intlayer ships a CLI to test for missing translations, an LSP, an MCP server and agent skills.
Translate missing messages in your CI/CD pipeline with the LLM of your choice, or in the background with the web platform.
Intlayer provides a self-hosted visual editor and a full CMS so translators and copywriters can edit content in real time.
To understand where these libraries come from, read the history of JavaScript i18n.
Migration strategies
- Compat adapter (recommended for existing apps): Install
@intlayer/svelte-i18n. It exposes the same API assvelte-i18n(init,locale,$_/$t,$json,$date,$time,$number,getLocaleFromNavigator…) and serves messages from Intlayer dictionaries. ICU MessageFormat works as before. - Full migration: Gradually replace svelte-i18n stores with
useIntlayerfromsvelte-intlayerand.content.tsfiles co-located with your components.
Table of Contents
Quick migration
Install Dependencies
bashCopy codeCopy the code to the clipboard
The
--interactiveflag is optional. Useintlayer-cli initif you're an AI agent.The command detects your environment and installs the required packages, for example:
bashCopy codeCopy the code to the clipboard
Keep
svelte-i18ninstalled: it provides the TypeScript types.Configure Intlayer
Point the
syncJSONplugin at your existing message files. With one file per namespace (src/locales/en/home.json), each file becomes a dictionary:intlayer.config.tsCopy codeCopy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer"; import { syncJSON } from "@intlayer/sync-json-plugin"; const config: IntlayerConfig = { internationalization: { locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], defaultLocale: Locales.ENGLISH, }, plugins: [ syncJSON({ // svelte-i18n uses ICU MessageFormat format: "icu", // ./src/locales/en/home.json → dictionary `home` source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`, }), ], }; export default config;$_('home.title')resolves to thetitlefield of thehomedictionary. If you use a single file per locale (src/locales/en.json) with nested namespaces, usesource: ({ locale }) => `./src/locales/${locale}.json`instead: each top-level key becomes a dictionary.Add the Vite plugin
svelteI18nVitePlugin()runs the Intlayer build and aliasessvelte-i18nto@intlayer/svelte-i18n, so no source file changes are needed.vite.config.tsCopy codeCopy the code to the clipboard
import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; import { svelteI18nVitePlugin } from "@intlayer/svelte-i18n/plugin"; export default defineConfig({ plugins: [svelte(), svelteI18nVitePlugin()], });For SvelteKit, add
svelteI18nVitePlugin()aftersveltekit()in the samepluginsarray.Simplify the i18n setup
Keep
init(), but removeregister()andaddMessages(): messages come from Intlayer dictionaries.src/lib/i18n.tsCopy codeCopy the code to the clipboard
Your components keep working unchanged:
Copy the code to the clipboard
Setting $locale = 'fr' switches the language for both svelte-i18n stores and useIntlayer.
Complete migration
Explicit import renaming (optional)
OptionalThe Vite plugin already handles aliasing. To make the dependency explicit:
Show all table contentOpen the table in a modal to view all data content clearly
Before After import { _, t } from 'svelte-i18n'import { _, t } from '@intlayer/svelte-i18n'import { locale } from 'svelte-i18n'import { locale } from '@intlayer/svelte-i18n'import { init } from 'svelte-i18n'import { init } from '@intlayer/svelte-i18n'import { date, number } from 'svelte-i18n'import { date, number } from '@intlayer/svelte-i18n'Move content to .content.ts files
OptionalNew components can use native Intlayer content, side by side with existing svelte-i18n calls:
src/lib/home.content.tsCopy codeCopy the code to the clipboard
src/lib/Home.svelteCopy codeCopy the code to the clipboard
Enable AI-powered translation
OptionalbashCopy codeCopy the code to the clipboard
Filled translations are written back to your JSON files. See the CLI documentation for AI configuration.
What you can delete after migration
Open the table in a modal to view all data content clearly
| File / pattern | Why it's no longer needed |
|---|---|
register() / addMessages() calls | Dictionaries are compiled and loaded by Intlayer. |
waitLocale() before rendering | Messages are available as soon as the locale is set. |
Configure TypeScript
Include the generated types in your tsconfig.json:
Copy the code to the clipboard
Git Configuration
Copy the code to the clipboard
