Before you start, ensure you have the following installed:
Verify the installations by running the following commands:
First, create a new Angular project and install ngx-translate and the necessary HTTP loader:
Update your file app.module.ts and configure the TranslateModule:
Create translation files for different regions. For example, create en-US.json and en-GB.json in the assets/i18n directory.
Inject TranslateService in your app.component.ts and use it to switch languages dynamically.
Use the translate pipe to translate text in your Angular templates:
*Note that the translation keys are defined in the src/assets/i18n/en-US.json and src/assets/i18n/en-GB.json file.
app.component.html
Run your Angular application using the following command:
Open your browser and navigate to http://localhost:4200 to view your application.
Open your browser and change the language like below:
en-US.json

Changing language to en-GB

Moving en-GB to default language

Reload the Page

Now we can support multiple languages and resonate with diverse cultural contexts. This powerful library allows effortless integration of translation capabilities, dynamic content management, and a seamless global user experience.
Want to see the code from this tutorial in action? PULL the complete working example from my GitHub repository!
![]()
© 2024 PullStackDeveloper. All rights reserved.