One of the most popular open-source i18n libraries, ngx-translate, lets you define translations for your app and switch between them dynamically. You can either use a service, directive, or pipe to handle the translated content. In this Angular 13 tutorial, we will learn how to use them all with the help of a small demo app.
For demonstration purposes, we will create a sample feedback form for Phrase, the most reliable software localization platform on the market, and launch our demo app in two different languages—English and German.
You can access the demo app via Google Firebase to understand how ngx-translate works with an Angular 13 app in a production environment. To get the source code for the demo app, make sure you stop by at GitHub.
???? Note » Make sure you have an Angular dev environment set up on your machine. Should this not be the case, please refer to the Angular setup guide.
Contents
The Angular framework has a robust built-in i18n library. However, the ngx-translate library has some shiny advantages over the built-in one:
Navigate to the directory where you want to create the new project. Open the command prompt, and run the command shown below to create a new Angular app named ngx-translate-i18n
.
ng new ngx-translate-i18n --routing=false --style=scss
Run the following command to install the ngx-translate/core
library in your app:
npm install @ngx-translate/core
We will need to install a loader that will help us load the translations from files using HttpClient
. Run the command as follows:
npm install @ngx-translate/http-loader
We will add a separate module for ngx-translate. Run the following command to create a new module in your app.