Source: https://paraglidejs.com/migrating-from-ngx-translate

# Migrating from ngx-translate

**To migrate an Angular app from ngx-translate to Paraglide JS, compile your existing `assets/i18n/{locale}.json` files with Paraglide (the i18next plugin reads ngx-translate's `{{param}}` syntax and nested keys), then replace `'KEY' | translate` and `translate.instant('KEY')` with typed calls like `m['KEY']()`. Both libraries can read the same files while you move components over.**

```bash
npm install -D @inlang/paraglide-js
```

## Paraglide vs ngx-translate

[ngx-translate](https://ngx-translate.org/) is a widely used runtime i18n library for Angular, and it is actively maintained: v18 supports Angular 18 through 22 and adds signal-based APIs. It loads JSON files at runtime (usually over HTTP) and resolves keys when the template renders. Paraglide compiles the same messages at build time into typed functions.

- **Choose Paraglide** for compile-time checks on keys and parameters, translations bundled with the code (no HTTP loader, no loading state), unused-message tree-shaking, and built-in plurals and selects.
- **Stay on ngx-translate** if translations must change without a rebuild, you switch language without reloading and need to keep in-memory state, or you depend on its plugin ecosystem (custom loaders, compilers, missing-translation handlers).

| | Paraglide JS | ngx-translate |
| --- | --- | --- |
| **Architecture** | Compiler: one generated function per message | Runtime: loader fetches JSON, parser interpolates |
| **In templates** | `{{ m['HOME.TITLE']() }}` | `{{ 'HOME.TITLE' \| translate }}` |
| **In TypeScript** | `m['HOME.TITLE']()` (synchronous) | `translate.instant()`, `get()`, `stream()`, `translate()` signal |
| **Typed keys and parameters** | ✅ Generated | ❌ Keys are strings |
| **Loading** | Bundled with the code; unused messages removed | Fetched at runtime per language; `isLoading` until ready |
| **Plurals / select** | ✅ Built in ([variants](https://paraglidejs.com/variants)) | Via [ngx-translate-messageformat-compiler](https://github.com/lephyrus/ngx-translate-messageformat-compiler) |
| **Locale switching** | `setLocale()` navigates or reloads the page | `translate.use()` updates in place |
| **Translations without a rebuild** | ❌ | ✅ |
| **Translation workflow** | [General Translation through the inlang CLI](https://paraglidejs.com/translating-messages), Fink editor, Sherlock VS Code extension | JSON files; [BabelEdit](https://www.codeandweb.com/babeledit), [ngx-translate-extract](https://github.com/ngx-translate/extract) |

The rest of this page is the migration.

## Overview

| ngx-translate | Paraglide JS |
| --- | --- |
| `public/i18n/en.json` or `src/assets/i18n/en.json` | Same files, read by the [i18next plugin](https://inlang.com/m/3i8bor92/plugin-inlang-i18next) |
| `"HELLO": "Hello {{name}}"` | Unchanged; compiles to `m.HELLO({ name })` |
| Nested `{ "HOME": { "TITLE": … } }` | Unchanged; compiles to `m['HOME.TITLE']()` |
| `provideTranslateService({ lang, fallbackLang, loader })` | `project.inlang/settings.json` (`baseLocale`, `locales`) and a [locale strategy](https://paraglidejs.com/strategy) |
| `provideTranslateHttpLoader(...)` | Remove; messages are compiled into the bundle |
| `TranslatePipe`, `TranslateDirective` | Expose `m` on the component |
| `TranslateMessageFormatCompiler` (ICU) | ICU plugin (see [ICU messages](#icu-messages)) |

## 1. Set up Paraglide

Install Paraglide and create `project.inlang/settings.json`. Point the [i18next plugin](https://inlang.com/m/3i8bor92/plugin-inlang-i18next) at your existing files; adjust `pathPattern` to where they are:

```json
{
  "baseLocale": "en",
  "locales": ["en", "de", "fr"],
  "modules": ["https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@6.5.6/dist/index.js"],
  "plugin.inlang.i18next": {
    "pathPattern": "./public/i18n/{locale}.json",
    "contextValues": []
  }
}
```

The plugin reads `{{name}}` and `{{ name }}` placeholders and nested or flat dotted keys, and writes translations back in the same structure. `"contextValues": []` stops it from reading key suffixes like `SHIPPING_FREE` as an i18next [context](https://www.i18next.com/translation-function/context) of `SHIPPING`; keep it unless you use i18next contexts.

Angular's build doesn't run Paraglide's Vite plugin, so compile with the CLI before serving and building:

```json
{
  "scripts": {
    "i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --strategy cookie preferredLanguage baseLocale",
    "start": "npm run i18n:compile && ng serve",
    "build": "npm run i18n:compile && ng build"
  }
}
```

Add `paraglide-js compile ... --watch` alongside `ng serve` if you edit messages while the dev server runs. The [strategy](https://paraglidejs.com/strategy) above remembers the chosen language in a cookie and falls back to the browser language, like a typical `translate.getBrowserLang()` setup. For Angular SSR, the locale has to be resolved per request with `paraglideMiddleware`; see [server-side rendering](https://paraglidejs.com/server-side-rendering).

### Check your keys and parameters

Most ngx-translate files compile as they are. Check for three things:

- **Lowercase plural suffixes.** The i18next plugin reads keys ending in `_zero`, `_one`, `_two`, `_few`, `_many` or `_other` (lowercase) as plural forms of one message. `item_one` and `item_other` become `m.item({ count })`. Rename such keys if they aren't plurals. Uppercase keys like `STEP_ONE` are not affected.
- **Dotted parameters.** ngx-translate resolves `{{user.name}}` from nested params. Paraglide parameters are flat, so `{{user.name}}` becomes a parameter literally named `"user.name"`. Rename it to `{{userName}}` and pass `{ userName: user.name }`; ngx-translate accepts that too.
- **`{{` in plain text.** Any `{{ … }}` is read as a placeholder, as in ngx-translate.

Compile once with `npm run i18n:compile`; the generated `src/paraglide/messages.js` exports one function per key.

### ICU messages

If you use [ngx-translate-messageformat-compiler](https://github.com/lephyrus/ngx-translate-messageformat-compiler), your messages are ICU MessageFormat (`{count, plural, one {# item} other {# items}}`) with single-brace placeholders. Use the [ICU MessageFormat plugin](https://inlang.com/m/p7c8m1d2/plugin-inlang-icu-messageformat-1) instead of the i18next plugin. It reads top-level keys only, so flatten nested files to dotted keys first; ngx-translate reads flat dotted keys as well. The [svelte-i18n migration guide](https://paraglidejs.com/migrating-from-svelte-i18n#flatten-nested-keys) has a flatten script and the plugin configuration.

## 2. Replace call sites

Expose the generated messages on each component instead of importing `TranslatePipe`:

```ts
import { Component } from "@angular/core";
import { m } from "../paraglide/messages.js";

@Component({
  selector: "app-home",
  templateUrl: "./home.html",
})
export class Home {
  protected readonly m = m;
  protected readonly user = { name: "Ada" };
}
```

```html
<h1>{{ m['HOME.TITLE']() }}</h1>
<p>{{ m['HOME.HELLO']({ name: user.name }) }}</p>
```

Messages are plain functions that return strings, so they work with `OnPush` and zoneless change detection: the locale doesn't change while the page is open.

| ngx-translate | Paraglide JS |
| --- | --- |
| `{{ 'HOME.TITLE' \| translate }}` | `{{ m['HOME.TITLE']() }}` |
| `{{ 'HOME.HELLO' \| translate: { name } }}` | `{{ m['HOME.HELLO']({ name }) }}` |
| `<div [translate]="'HOME.HELLO'" [translateParams]="{ name }"></div>` | `<div>{{ m['HOME.HELLO']({ name }) }}</div>` |
| `[title]="'HOME.TITLE' \| translate"` | `[title]="m['HOME.TITLE']()"` |
| `translate.instant('HOME.TITLE', params)` | `m['HOME.TITLE'](https://github.com/opral/paraglide-js/blob/main/docs/params)` |
| `translate.get(key)`, `translate.stream(key)` | `m[...]()` (synchronous; wrap in `of()` if an API needs an Observable) |
| `translate.use('de')` | `setLocale('de')` from `paraglide/runtime.js` (navigates or reloads) |
| `translate.currentLang()` | `getLocale()` |
| `translate.getLangs()` | `locales` from `paraglide/runtime.js` |
| `translate.setFallbackLang('en')` | `baseLocale` in `project.inlang/settings.json` |
| `translate.onLangChange` | Not needed; a locale change loads a new page |
| `{{ key \| translate }}` with a variable key | A lookup object of message functions ([dynamic keys](https://paraglidejs.com/message-keys#working-with-dynamic-keys)) |

This Perl command rewrites `translate` pipes with a literal key in template interpolations, with no params, an object literal, or a variable. It turns `{{ 'HOME.TITLE' | translate }}` into `{{ m['HOME.TITLE']() }}` and `{{ 'HOME.HELLO' | translate: { name } }}` into `{{ m['HOME.HELLO']({ name }) }}`. Pipes in property bindings, chained pipes, and variable keys are left for you. Commit first and review the diff:

```bash
find src -name '*.html' -print0 | xargs -0 perl -pi -e 's{\{\{\s*([\x27"])([^\x27"]+)\1\s*\|\s*translate\s*(?::\s*(\{[^{}]*\}|[\w.]+)\s*)?\}\}}{my ($k, $v) = ($2, $3 // ""); "{{ " . ($k =~ /^[A-Za-z_]\w*$/ ? "m.$k" : "m[\x27$k\x27]") . "($v) }}"}ge'
```

Then add `protected readonly m = m;` and the import to each component, and search for what's left:

```bash
grep -rnE "\| *translate|translate(Params)?\]|\.instant\(|\.stream\(|translate\.get\(" src
```

`ng build` type-checks templates, so a misspelled key or missing parameter now fails the build.

## 3. Migrate incrementally (optional)

Both libraries read the same JSON files, so you can migrate one component at a time:

- Keep `provideTranslateService` until the last pipe is gone.
- Add new keys to the same files; both libraries see them after `i18n:compile`.
- Keep the two in the same language: pass `lang: getLocale()` to `provideTranslateService`, and switch languages with Paraglide's `setLocale()`.

See [incremental migration](https://paraglidejs.com/incremental-migration) for the general pattern.

## 4. Remove ngx-translate

When no ngx-translate APIs remain:

1. Remove `provideTranslateService(...)` and `provideTranslateHttpLoader(...)` from `app.config.ts`, and any `provideAppInitializer` that called `translate.use()`.
2. Uninstall the packages: `npm uninstall @ngx-translate/core @ngx-translate/http-loader` (and `ngx-translate-messageformat-compiler` if used).
3. If nothing else needs the JSON files at runtime, move them out of `public/` or `assets/` so they aren't deployed, and update `pathPattern`.

## 5. Translate missing locales with General Translation

The [inlang CLI](https://inlang.com/m/2qj2w8pu/app-inlang-cli) fills every missing key in your locale files, keeps `{{placeholders}}` intact, and updates translations whose source message changed. We recommend [General Translation](https://paraglidejs.com/translating-messages), the company that maintains Paraglide JS:

```bash
npx @inlang/cli machine translate --project ./project.inlang
```

The first run asks which provider to use; choose **General Translation** and sign in through your browser. Review the diff, then check the result:

```bash
npx @inlang/cli check --project ./project.inlang
```

[Translating messages](https://paraglidejs.com/translating-messages) covers CI, coding agents, and other providers.

## Next steps

- [Message keys](https://paraglidejs.com/message-keys) — flat vs nested keys, and dynamic keys
- [Variants](https://paraglidejs.com/variants) — plurals and selects without a separate compiler
- [Strategy](https://paraglidejs.com/strategy) — how the locale is detected and stored
- [Checking translations](https://paraglidejs.com/checking-translations) — fail CI on missing translations or unused messages
