Are you ready to empower your NX Angular libraries with seamless translation capabilities? Look no further than Transloco — the ultimate solution for integrating multilingual support into your projects! In this guide, we’ll explore how to effortlessly integrate Transloco and infuse your NX Angular libraries with Scoped Translation magic. Get ready to elevate your library’s language game effortlessly!
Let’s Dive In#
First things first — let’s set up our NX Workspace:
| |
We will use the following settings:
| |
Once your workspace is ready, generate a new library named lib-with-transloco.
| |
Integrate Transloco: A Smooth Ride#
Next, let’s integrate Transloco into your library:
| |
Craft a new class named TranslocoHttpLoader within nx-with-transloco/src/transloco-http.loader.ts and fill it with the provided code snippet.
| |
Update ./src/main.ts to include Transloco configuration and loader setup. It\’s as simple as copy-pasting the provided snippet!
| |
For further informations how to install and setup transloco correctly, please see: https://ngneat.github.io/transloco/docs/getting-started/installation
Scoped Translation: Unleash the Power#
Now, let’s infuse your library with Scoped Translation magic. Update lib-with-transloco.component.ts to include the TranslocoDirective in the imports section.
| |
Create the language files en.json and de.json within the i18n folder under your library directory, providing respective translations.
| |
Tweak the HTML of your library component to utilize a custom Transloco scope and serve translations from the JSON files.
| |
At this step we are finished with the adjustments to our library and we are pretty much ready to go. Next we need to do some small adjustments to the project itself, which should include the library:
In the app.component.ts of the application we are adding the LibWithTranslocoComponent to our imports, so we can use it in the HTML:
| |
In the HTML Code we just add the component:
| |
Until now, we have a library which is translated using the Transloco Translation Scope feature. But the files with the translations are not copied to the main application and do not get delivered to the customer. To copy the translation files, we are using the Angular feature to copy assets. We adjust the project.json of the main application under apps/nx-with-transloco/project.json we add the following content in the assets array:
| |
Important is, that the output directory needs to match the custom scope provided, in our case it is libScope.
At this point, our application is ready to go. If we run nx serve nx-with-transloco command, the application will be started and we can see the english translation of our library component.
We can tweak our application some bit and add two buttons for the language switch:
Add the following buttons to the app.component.html :
| |
And to execute the language switch, we adjust the TypeScript and add the following content:
| |
Now we are ready to go, when lunching the application, we can see the translated library component and can switch between the languages we’ve defined to support.

Conclusion: Elevate Your Library’s Language Experience#
With Transloco, integrating translations into your NX Angular libraries has never been easier. Follow these simple steps to enrich your library with multilingual support effortlessly. For the complete code, check out the GitHub repository linked below.
Get ready to create, translate, and inspire — your library is about to speak the world’s languages with ease!
Find the complete code on GitHub: https://github.com/schroedermarius/medium-nx-with-transloco
If you found this guide helpful, don’t forget to share it with fellow developers. Stay tuned for more insights and tutorials — the language revolution awaits!
