Install ngx-translate in Angular - Setup Guide
@ngx-translate/core v18 requires Angular 18 or newer. For detailed information about
compatibility with different Angular versions, see the
Angular Compatibility documentation.
To get started with Angular translation and internationalization (i18n), you can add the ngx-translate npm modules to your project:
npm i @ngx-translate/core @ngx-translate/http-loaderpnpm add @ngx-translate/core @ngx-translate/http-loaderyarn add @ngx-translate/core @ngx-translate/http-loader@ngx-translate/http-loader is optional. You can use it to load translation files on demand from your server.
ngx-translate works great with Angular’s modern standalone components for building multilingual applications. If you’re using NgModules, you can check out the NgModules Support documentation.
To use ngx-translate for Angular translation in your project, you’ll need to use the provideTranslateService() function in your appConfig:
import {ApplicationConfig, provideZoneChangeDetection} from "@angular/core";import {provideTranslateService} from "@ngx-translate/core";
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), provideTranslateService({ fallbackLang: 'en', lang: 'en' }) ],};For most applications, you’ll want to load translations from JSON files. The HTTP loader makes this easy:
import {ApplicationConfig, provideZoneChangeDetection} from "@angular/core";import {provideTranslateService} from "@ngx-translate/core";import {provideTranslateHttpLoader} from "@ngx-translate/http-loader";import {provideHttpClient} from "@angular/common/http";
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), provideHttpClient(), provideTranslateService({ loader: provideTranslateHttpLoader({ prefix: '/assets/i18n/', suffix: '.json' }), fallbackLang: 'en', lang: 'en' }) ],};Initialize the TranslateService for your application
Section titled “Initialize the TranslateService for your application”In your components, you’ll need to import TranslatePipe and TranslateDirective to your imports
(v18 also ships TranslateBlockDirective
for the *translateBlock structural directive — import it when you need it). You can access the
TranslateService using the modern inject() function:
import { Component, inject } from '@angular/core';import { TranslateService, TranslatePipe, TranslateDirective} from "@ngx-translate/core";
@Component({ selector: 'app-root', standalone: true, imports: [TranslatePipe, TranslateDirective], templateUrl: './app.component.html', styleUrls: ['./app.component.scss']})export class AppComponent { private translate = inject(TranslateService);
constructor() { // `lang` and `fallbackLang` from provideTranslateService() are already applied; // call addLangs() to register additional languages the user can switch to. this.translate.addLangs(['de', 'en']); }}Now, skip the next chapter: