Author:
    Creation:2026-11-23Last update:2026-11-23

    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

    1. Compat adapter (recommended for existing apps): Install @intlayer/svelte-i18n. It exposes the same API as svelte-i18n (init, locale, $_ / $t, $json, $date, $time, $number, getLocaleFromNavigator…) and serves messages from Intlayer dictionaries. ICU MessageFormat works as before.
    2. Full migration: Gradually replace svelte-i18n stores with useIntlayer from svelte-intlayer and .content.ts files co-located with your components.

    Table of Contents

    Quick migration

    1. Install Dependencies

      bash
      npx intlayer init --interactive
      
      The --interactive flag is optional. Use intlayer-cli init if you're an AI agent.

      The command detects your environment and installs the required packages, for example:

      bash
      npm install intlayer @intlayer/svelte-i18n @intlayer/sync-json-plugin
      
      Keep svelte-i18n installed: it provides the TypeScript types.
    2. Configure Intlayer

      Point the syncJSON plugin at your existing message files. With one file per namespace (src/locales/en/home.json), each file becomes a dictionary:

      intlayer.config.ts
      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 the title field of the home dictionary. If you use a single file per locale (src/locales/en.json) with nested namespaces, use source: ({ locale }) => `./src/locales/${locale}.json` instead: each top-level key becomes a dictionary.
    3. Add the Vite plugin

      svelteI18nVitePlugin() runs the Intlayer build and aliases svelte-i18n to @intlayer/svelte-i18n, so no source file changes are needed.

      vite.config.ts
      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() after sveltekit() in the same plugins array.
    4. Simplify the i18n setup

      Keep init(), but remove register() and addMessages(): messages come from Intlayer dictionaries.

      src/lib/i18n.ts
      import { getLocaleFromNavigator, init } from "svelte-i18n";
      
      init({
        fallbackLocale: "en",
        initialLocale: getLocaleFromNavigator(),
      });
      

    Your components keep working unchanged:

    src/App.svelte
    <script lang="ts">
      import { _, date, number } from "svelte-i18n";
    </script>
    
    <h1>{$_("home.title")}</h1>
    <p>{$_("home.greeting", { values: { name: "Ada" } })}</p>
    <p>{$date(new Date(), { format: "long" })}</p>
    <p>{$number(1234.5, { style: "currency", currency: "EUR" })}</p>
    

    Setting $locale = 'fr' switches the language for both svelte-i18n stores and useIntlayer.

    Complete migration

    1. Explicit import renaming (optional)

      Optional

      The Vite plugin already handles aliasing. To make the dependency explicit:

      BeforeAfter
      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'
    2. Move content to .content.ts files

      Optional

      New components can use native Intlayer content, side by side with existing svelte-i18n calls:

      src/lib/home.content.ts
      import { t, type Dictionary } from "intlayer";
      
      const homeContent = {
        key: "home",
        content: {
          title: t({ en: "Welcome", fr: "Bienvenue", es: "Bienvenido" }),
        },
      } satisfies Dictionary;
      
      export default homeContent;
      
      src/lib/Home.svelte
      <script lang="ts">
        import { useIntlayer } from "svelte-intlayer";
      
        const content = useIntlayer("home");
      </script>
      
      <h1>{$content.title}</h1>
      
    3. Enable AI-powered translation

      Optional
      bash
      # Test for missing translations (add to CI)
      npx intlayer test
      
      # Fill missing translations with AI
      npx intlayer fill
      

      Filled translations are written back to your JSON files. See the CLI documentation for AI configuration.

    What you can delete after migration

    File / patternWhy it's no longer needed
    register() / addMessages() callsDictionaries are compiled and loaded by Intlayer.
    waitLocale() before renderingMessages are available as soon as the locale is set.

    Configure TypeScript

    Include the generated types in your tsconfig.json:

    tsconfig.json
    {
      "include": [
        // ... your existing paths
        ".intlayer/**/*.ts",
      ],
    }
    

    Git Configuration

    .gitignore
    # Ignore the files generated by Intlayer
    .intlayer
    

    Go Further