Comments (5)
Hi Matthias,
-
Yes: because pipes are pure you have to extend
Locale
class that provides the values forlang
anddefaultLocale
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 thepure pipes
, see this post: #33 -
I 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: mgechev/codelyzer#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
from angular-l10n.
Hi Roberto,
thanks a lot for explaing things helping me out :)
- i know that inheriting is not a pollution in general, but i think it kind of restricts me from having my own super class and it is "a lot" of boilerplate code (if you have to do it in a lot of components). So thanks a lot for the hint with the HTML attributes, i think i'll go this way whereever i can. One thing that came up when i experimented with the HTML attributes:
i had to use
<div translate>foo</div>
and this didn't work:
<div translate>
foo
</div>
Probably because of the spaces - if there is no reason to keep it this way you might consider to trim the white spaces :)
- I'm not an expert creating own pipes and not sure why you used impure before, but since you already have the services available in the pipe - why not just use the value from the service?
Can you provide an example with Advanced Initialization or is this what you mean with it? I'd rather not "code" the translation, on the other hand i could just use seperate .ts files instead of json for that
Thanks and best regards,
Matthias
from angular-l10n.
Just saw #33, sorry :-)
from angular-l10n.
No problem.
-
About the Html attributes, I'll evaluate to trim the white spaces in the next release. Thanks for the tip!
-
We can't use the value from the service because the
transform
method of a pure pipe is invoked by Angular Change Detection mechanism only when the input parameters change.
Greetings,
Roberto
from angular-l10n.
I'm closing it. If you need, open a new issue. Greetings
from angular-l10n.
Related Issues (20)
- Function calls are not supported in decorators but 'L10nTranslationModule' was called HOT 2
- How i can translate the word HOT 1
- feature: easily register and bundle translation data with a lazy loaded module HOT 3
- Number format options HOT 7
- Release a version with peerDependencies compatible with RxJS v7 HOT 3
- split big files HOT 2
- Namespace 'Intl' has no exported member 'RelativeTimeFormatOptions' HOT 3
- [Question] Differences / Benefits vs ngx-translate? HOT 3
- Setting available languages from Database HOT 5
- Problems after Upgrading HOT 2
- locale.language is empty, Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found HOT 2
- Incorrect date format HOT 2
- Namespace 'Intl' has no exported member 'ListFormatOptions' HOT 1
- possibility to configure PARSE_DATE_STYLE const. Configure full, long,medium,short options HOT 2
- Refreshing page redirects to fallback HOT 5
- Opening subpages in tabs works - sometimes HOT 1
- I encountered this problem: Unexpected value 'TranslateModule' imported by the module 'SharedModule'. Please add an @NgModule annotation. HOT 2
- angular-l10n used in angular component being imported from react parent application as library doesnot work HOT 8
- Is it possible to use angular-l10n to support custom translations in library1 while the config for translations stays in the main app that uses library1? HOT 10
- Json file convertion to js chunk creates a sublevel: [lang]_default HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-l10n.