Introduction
In this article, we will learn how to create angular applications using ngx-translate.
Steps:
Step 1
Create an Angular project setup using the below command or however you want to create it.
ng new projectname
Example:
ng new ngx-new

Step 2
Now, we must install @ngx-translate/core in our Angular app. Open a new terminal and run the below command.
npm i @ngx-translate/core
Now we can use ngx-translate in our Angular project. Then, we have to import TranslateModule.forRoot() in the root NgModule of your application.
- import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
TranslateModule.forRoot()
Step 3
Now, we must install @ngx-translate/http-loader in our Angular app. Open a new terminal and run the below command.
npm i @ngx-translate/http-loader

The TranslateHttpLoader uses HttpClient to load translations, it means that you have to import the HttpClientModule from @angular/common/http before the TranslateModule,
app.module.ts
- import {
- BrowserModule
- } from '@angular/platform-browser';
- import {
- NgModule
- } from '@angular/core';
- import {
- AppRoutingModule
- } from './app-routing.module';
- import {
- AppComponent
- } from './app.component';
- import {
- HttpClient,
- HttpClientModule
- } from '@angular/common/http';
- import {
- TranslateModule,
- TranslateLoader
- } from '@ngx-translate/core';
- import {
- TranslateHttpLoader
- } from '@ngx-translate/http-loader';
- export function HttpLoaderFactory(httpClient: HttpClient) {
- return new TranslateHttpLoader(httpClient);
- }
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- AppRoutingModule,
- HttpClientModule,
- TranslateModule.forRoot({
- loader: {
- provide: TranslateLoader,
- useFactory: HttpLoaderFactory,
- deps: [HttpClient]
- }
- })
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule {}
Step 4
Now, we can use folder assets, then whatever language we want to create a separate JSON.
In this article, we are doing two languages:



Join the conversation! Your thoughts help the community grow.