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

    Migrating from ngx-translate to Intlayer

    Why migrate from ngx-translate to Intlayer?

    ngx-translate fetches locale files at runtime through TranslateHttpLoader, which delays the first render. Intlayer compiles dictionaries at build time, so translations are available immediately.

    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/ngx-translate. It exposes the same API as @ngx-translate/core (provideTranslateService, TranslateService, TranslatePipe, TranslateDirective, TranslateModule) and serves messages from Intlayer dictionaries. Your templates stay unchanged.
    2. Full migration: Gradually replace ngx-translate calls with useIntlayer from angular-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 angular-intlayer @intlayer/ngx-translate @intlayer/sync-json-plugin
      npm install -D @angular-builders/custom-esbuild
      
      Keep @ngx-translate/core installed: it provides the TypeScript types. @ngx-translate/http-loader can be removed.
    2. Configure Intlayer

      Point the syncJSON plugin at your existing translation files. With one file per namespace (src/i18n/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({
            // matches ngx-translate placeholder syntax: {{name}}
            format: "i18next",
            // ./src/i18n/en/home.json → dictionary `home`
            source: ({ key, locale }) => `./src/i18n/${locale}/${key}.json`,
          }),
        ],
      };
      
      export default config;
      
      'home.title' | translate resolves to the title field of the home dictionary. If you use a single file per locale (src/assets/i18n/en.json) with nested keys, use source: ({ locale }) => `./src/assets/i18n/${locale}.json` instead: each top-level key becomes a dictionary.
    3. Add the esbuild plugin

      The Angular CLI accepts esbuild plugins through @angular-builders/custom-esbuild. Create a plugins file:

      esbuild.plugins.ts
      import { ngxTranslateEsbuildPlugin } from "@intlayer/ngx-translate/esbuild";
      
      export default [ngxTranslateEsbuildPlugin()];
      

      Then reference it in angular.json:

      angular.json
      {
        "architect": {
          "build": {
            "builder": "@angular-builders/custom-esbuild:application",
            "options": {
              "plugins": ["./esbuild.plugins.ts"],
              // ... your existing options
            },
          },
          "serve": {
            "builder": "@angular-builders/custom-esbuild:dev-server",
          },
        },
      }
      

      The plugin runs the Intlayer build and resolves @ngx-translate/core to @intlayer/ngx-translate, so no source file changes are needed.

      Building with Vite (Analog)? Use ngxTranslateVitePlugin() from @intlayer/ngx-translate/plugin instead.
    4. Remove the HTTP loader

      Keep provideTranslateService(), but drop the loader option: messages come from Intlayer dictionaries.

      src/app/app.config.ts
      import type { ApplicationConfig } from "@angular/core";
      import { provideTranslateService } from "@ngx-translate/core";
      
      export const appConfig: ApplicationConfig = {
        providers: [
          provideTranslateService({
            lang: "en",
            fallbackLang: "en",
          }),
        ],
      };
      
      Translations no longer go through a loader, so TranslateHttpLoader and @ngx-translate/http-loader can be removed.

    Your templates and services keep working unchanged:

    src/app/app.html
    <h1>{{ 'home.title' | translate }}</h1>
    <p [translate]="'home.greeting'" [translateParams]="{ name: 'Ada' }"></p>
    <h2 translate>home.serviceSection</h2>
    
    src/app/app.ts
    import { Component, inject } from "@angular/core";
    import { TranslatePipe, TranslateService } from "@ngx-translate/core";
    
    @Component({
      selector: "app-root",
      imports: [TranslatePipe],
      templateUrl: "./app.html",
    })
    export class App {
      private readonly translate = inject(TranslateService);
    
      readonly message = this.translate.instant("home.title");
    
      switchTo = (lang: string) => this.translate.use(lang);
    }
    

    Complete migration

    1. Explicit import renaming (optional)

      Optional

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

      BeforeAfter
      import { TranslateService } from '@ngx-translate/core'import { TranslateService } from '@intlayer/ngx-translate'
      import { TranslatePipe } from '@ngx-translate/core'import { TranslatePipe } from '@intlayer/ngx-translate'
      import { provideTranslateService } from '@ngx-translate/core'import { provideTranslateService } from '@intlayer/ngx-translate'
    2. Move content to .content.ts files

      Optional

      New components can use native Intlayer content, side by side with existing ngx-translate calls. Register provideIntlayer() from angular-intlayer next to provideTranslateService() in app.config.ts, then:

      src/app/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/app/home.component.ts
      import { Component } from "@angular/core";
      import { useIntlayer } from "angular-intlayer";
      
      @Component({
        selector: "app-home",
        template: `<h1>{{ content().title }}</h1>`,
      })
      export class HomeComponent {
        content = useIntlayer("home");
      }
      
    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
    TranslateHttpLoader / custom loadersDictionaries are compiled and loaded by Intlayer.
    @ngx-translate/http-loaderNo runtime fetch of translation files.
    provideHttpClient() (if only used for translations)Same reason.

    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