Questions/Feature Request: "polluting" components / translate pipe without language parameter
See original GitHub issueI use your great localization library accross multiple modules and components and setup everything in my AppModule including setting the locale/language like described [here] + setCurrentLocale().(https://github.com/robisim74/angular2localization/blob/master/doc/quick-start.md)
So far, so good, now my questions regarding using it:
-
Do i have to pollute" all my components with extends locale and so on? It seems to work without it which i would highly appreciate
-
If i don’t have to pollute my components, there is an issue with the lang parameter of the translate pipe:
- ideally i just want to do this:
{{ 'foo' | translate }}so that the language that has been setup on bootstrap is used. But currently the texts are not translated and i get an empty output - using {{ ‘foo’ | translate:lang }} i have two options:
- get the current lang parameter from the locale service --> pollutes my code again 😦
- just dont provide the lang property in my component.ts, so that it is null and the fallback is used
- unfortunately tslint will tell me that i use an invalid property 😦
- my current solution is to turn off the tslint warning, which is also not so good.
Can you make the lang parameter optional so that the default is beeing used? Might also be related to #45
Is there already a working solution for this?
Thanks and best regards, Matthias
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
Hi Matthias,
Yes: because pipes are pure you have to extend
Localeclass that provides the values forlanganddefaultLocaleparameters. It’s normal to use inheritance in OOP, and it isn’t a pollution. Alternatively, you can use Html attributes: https://github.com/robisim74/angular2localization/blob/master/doc/spec.md#2.4 (and you can use the pipes only when you can not use Html attributes, as with the placeholders etc.) To know why this project is passed to thepure pipes, see this post: https://github.com/robisim74/angular2localization/issues/33I don’t know a way to use only
{{ 'foo' | translate }}usingpure pipes: I tried in every way, without success. About TSLint/Codelyzer, I have already opened this issue: https://github.com/mgechev/codelyzer/issues/191The value of
langis already optional (not the parameter), and the default language is already used: but without it, and without extending theLocaleclass:Greetings,
Roberto
I’m closing it. If you need, open a new issue. Greetings