core
core copied to clipboard
Translate in a given language
Hello,
I have a specific need and I don't find a solution with no downside. Maybe I just missed something but I can't find what.
My need: get a translation in a lang different than the currently used language. (example: app in english, need just one translation in french)
I found 2 ways of doing it:
- Change the entire app language (TranslateService.use), retrieve the traduction and set back the original language.
- Retrieve all the translations of the given language and manually find what I need (TranslateService. getTranslation).
I don't like the first approach because the entire app lang is changed and I can't be sure that angular is not trying to get a translation during that process (would cause a wrong translation if it happens) For the second approach, the interpolation is not longer possible (or must be done manually).
Is there an easier way to do it ?
Hi X4V1, you can create your own custom loader, load more than one resource and merge them as needed. Take a look at my article where I use this trick to make translations much more modular, but the loader I implemented should help you get started on a good idea. Angular: Modular translations