ngx-translate

The preset for ngx-translate. It reads the translate pipe and directive in Angular templates, and TranslateService calls.

The ngx-translate preset supports ngx-translate in Angular projects.

Detection

The preset applies when the project depends on @ngx-translate/core.

x18n.config.ts
import { ngxTranslate } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: [ngxTranslate()],
})

Locale files

If your config has no resources, the preset uses src/assets/i18n/{locale}.json and src/assets/i18n/{locale}/{namespaces}.json.

Supported syntax

In HTML templates, the preset reads the translate pipe and the translate directive:

src/app/app.component.html
<h1>{{ 'home.title' | translate }}</h1>
<p [translate]="'home.sub'"></p>
<p translate="home.intro"></p>
<span translate>home.footer</span>

In TS and JS files, these names count as translate calls: translate.instant, translate.get, translate.stream, translateService.instant, translateService.get, translateService.stream and _. A call on this counts too:

src/app/app.component.ts
this.translate.instant('home.save')

Placeholders

Double braces: {{name}}.

Extraction templates

KindsTemplate
html-text{{ '{key}' | translate }}
js-string, js-templatethis.translate.instant('{key}'{args})