Hack the Library
In Transloco, you can extend and customize its behavior through several mechanisms: the loader, interceptor, missing handler, and fallback strategy. These tools allow you to control how translations are loaded, how translation data is processed before it's saved, how missing keys are handled, and how fallback languages are selected when the primary language fails to load.
This flexibility ensures that you can tailor Transloco to meet the specific needs of your application, whether you need to load translations from custom sources, manipulate translation data, or handle missing translations in a way that suits your use case.
Below are explanations and examples of how to implement and customize these features.
The Loader
The loader allows you to override the default behavior of loading translation files.
The Interceptor
The interceptor gives you the ability to manipulate the translation object before it is saved by the service.
Missing Handler
The missing handler is responsible for handling missing keys. By default, it logs a warning in the console when config.isProdMode
is set to false
and returns an empty string for missing key values.
Fallback Strategy
The fallback strategy is responsible for loading a fallback translation file if the selected active language fails to load. By default, it loads the language set in config.fallbackLang
and uses it as the new active language.
If you need more control, you can define your own strategy:
The getNextLangs
method is called with the failed language and should return an array of languages to load, in order of preference.
Last updated