question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Questions/Feature Request: "polluting" components / translate pipe without language parameter

See original GitHub issue

I 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:

  1. 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

  2. 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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robisim74commented, Jan 7, 2017

Hi Matthias,

  1. Yes: because pipes are pure you have to extend Locale class that provides the values for lang and defaultLocale parameters. 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 the pure pipes, see this post: https://github.com/robisim74/angular2localization/issues/33

  2. I don’t know a way to use only {{ 'foo' | translate }} using pure pipes: I tried in every way, without success. About TSLint/Codelyzer, I have already opened this issue: https://github.com/mgechev/codelyzer/issues/191

The value of lang is already optional (not the parameter), and the default language is already used: but without it, and without extending the Locale class:

  • you have to use Advanced initialization to make sure the app is rendered after the http request of the json files is completed
  • you can’t change language at runtime (you need a new bootstrap of the application)

Greetings,

Roberto

0reactions
robisim74commented, Jan 30, 2017

I’m closing it. If you need, open a new issue. Greetings

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR in : The pipe 'translate' could not be found
I am using Angular 7.1 but unfortunately I am not able to make the translate pipe of ngx-translate to work… I can see...
Read more >
Prepare component for translation - Angular
To prepare your project for translation, complete the following actions. Use the i18n attribute to mark text in component templates; Use the i18n-...
Read more >
Federal Register Vol. 80, No.162,
Federal Register Volume 80, Issue 162 (August 21, 2015) ; 80 FR 50846 - Commission Information Collection Activities (FERC-725); Comment Request; Extension, PDF....
Read more >
ACT Prep Guide: - Phoenix Union High School District
the information presented, you will become familiar with not only the question types that will appear on the ACT, but also the language...
Read more >
Introduction to Sociology - Amazon S3
If you redistribute this textbook in a digital format (including but not limited to ... According to this sociological viewpoint, the parts of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found