Scope Configuration
Important Note that scopes follow Angular DI rules. They only work when declared in a lazy load module, or a component's providers.
Let's say we have a "todos" page, and we want to create separate translation files for this page that load only when the user navigates there. To achieve this, we first create a todos
folder (or any name of your choice) and place a translation file for each language we want to support:
There are three levels of setting the translation scope:
Lazy Module Providers
Component Providers
Inline Input
Lazy Module Providers
You can set the translation scope inside the lazy-loaded route providers. Here's how to do it for the todos
route:
Component Providers
Alternatively, you can define the translation scope directly in the componentโs providers:
Inline Input
You can also specify the translation scope inline using the scope
input in the transloco
structural directive:
How It Works
Each of these methods tells Transloco to load the corresponding scope based on the active language and merge it under the scope namespace into the active language translation object.
For example, if the active language is English (en
), Transloco will load the todos/en.json
file and set the translation as follows:
You can access these keys using the todos
namespace:
Scope's Namespace
By default, the namespace will be the scopeโs name in camel-case. You can preserve the original casing by configuring the scope.keepCasing
option.
Alternatively, you can provide a custom namespace for the scope by specifying an alias name in the module or component provider:
Then, you can access the translations via the customName
alias instead of the original todos
scope:
Last updated