Multiple Languages Simultaneously
There are times you may need to use a different language in a specific part of the template, or in a particular component or module. This can be achieved in a similar way to the previous example, except here set the TRANSLOCO_LANG
provider either in lazy module providers list, the component providers or in the template.
Here's an example of setting it in a component's providers:
my-comp.component.ts
Using Angular's DI rules, this will ensure that the language in this component's template and all of its children's templates is es
.
Alternatively, here is how to use it directly in the template:
my-comp.component.html
Note that it will be used as the initial language. If you need it to be static, you can use the static
pipe:
my-comp.component.ts
Or in the template:
my-comp.component.html