lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 29 forks source link

Global parameters / missing parameter handler #50

Open revenz opened 4 years ago

revenz commented 4 years ago

I'm wanting to use global parameters in translation strings, things I don't have to pass in all the time. eg . {ProductName} etc, where any string can just use that and it will be translated.

Either some kinda of global parameters, or a missing parameter handler where I can set these, or a pre-translate event where i can alter the passed in parameters adding the global ones there.

Is there any current way to do this?

lephyrus commented 4 years ago

That's an interesting idea, sounds useful. There's currently no way to do this that I'm aware of.

lemoinem commented 4 years ago

We have the same issue. The way we do it, is by using a custom loader and doing the replace when the translations are loaded.

Of course, that means we can't update the value of these parameters if they ever change during the lifetime of the app (unless the translations are reloaded).

revenz commented 4 years ago

I just ended up writing a wrapper class, in that wrapper class adding the common translation parameters to the parameters (or creating parameters if null), then call the translate service. works well enough, and live translations as we need. just would be nice if this was baked in, because I could see it being useful.