jsverse / transloco

🚀 😍 The internationalization (i18n) library for Angular
https://jsverse.github.io/transloco/
MIT License
1.97k stars 191 forks source link

Feature(messageformat): Global variables for message formats #778

Open bartoszredziniak opened 2 days ago

bartoszredziniak commented 2 days ago

Is there an existing issue for this?

Which Transloco package(s) will this feature affect?

Transloco, MessageFormat

Is your feature request related to a problem? Please describe

No response

Describe the solution you'd like

I want to have the possibility to declare global variables, which can be used in select translations with MessageFormat. For example, I want to have a translation like this: { "mySelectRule": "{myVar, select, val1 {Value 1} val2 {Value 2} other {Other Value}}" } And use it without having to declare params in each use in the template: {{ 'mySelectRule' | transloco }} I'd like to set this param in a service or component class for each translation as a global param, e.g.: this.translocoService.setGlobalParam('myVar', 'val2') Currently, I have to pass this value each time, even though it is often the same value: {{ 'mySelectRule' | transloco : {myVar: 'val2'} }} This can be very useful, e.g., with user gender, because a lot of content can depend on this value.

Describe alternatives you've considered

Alternatively, it would be nice to be able to create an interceptor that could modify parameters before translation(something like headers in http interceptor)

Additional context

No response

I would like to make a pull request for this feature

No