Comments (16)
@FabienDehopre Thanks for reporting. I'll update you when I'll release the new version
from angular-l10n.
Tonight I'll release the new minor version. In a few days the new major version. Both will have this features.
from angular-l10n.
I don't know why you are using OnPush change detection strategy, but it's normal that the pure pipes don't work if you use it, because the input parameter (lang
) is updated by an event when the http request is completed.
from angular-l10n.
It seems odd to me because I use other pure pipe in my components with OnPush change detection strategy and I don't have any issue.
In the first place, I use the OnPush change detection strategy for performance reason. I have long list of bound items.
Also, I use @ngrx/store for my state management.. so I might store the current language and locale in my store and subscribe to your observables/events to update the central application store. Or temporarily disable onpush on my components
from angular-l10n.
I may have found a solution: because the input parameter is updated by a subscription, I can add the calling to the markForCheck
API in the Locale
class in this way:
constructor(public locale?: LocaleService, public localization?: LocalizationService, public changeDetectorRef?: ChangeDetectorRef) {
if (this.localization != null) {
this.lang = this.localization.languageCode;
// When the language changes, subscribes to the event & updates lang property.
this.localization.translationChanged.subscribe(
// Generator or next.
(language: string) => {
this.lang = language;
if (this.changeDetectorRef) { this.changeDetectorRef.markForCheck() }; // OnPush Change Detection strategy.
}
);
}
...
But then you have to pass a new parameter to the Locale
superclass when you use in the component changeDetection: ChangeDetectionStrategy.OnPush
:
constructor(public locale: LocaleService, public localization: LocalizationService, public cd: ChangeDetectorRef) {
super(locale, localization, cd);
What do you think?
from angular-l10n.
I think it's a good idea.
It's not a big deal to pass one more argument to the base class.
I already have base classes for my services with more than 3 arguments in the super constructor.
from angular-l10n.
I made the commit that adds support for OnPush Change Detection strategy.
You should remove the library from your npm modules, and follow the instructions in the README to build & install the library locally.
Please, try it in your app, and let me know if it works fine, so I'll include this support in the next release.
P.S. Just to explain: because the input parameter of the pure pipes changes when the http request is completed (ie after the event has been generated), markForCheck
method generates an event that allows the OnPush strategy to update the value. More explanation here: https://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html
from angular-l10n.
ok. I will test your change monday morning.
I'll keep you posted.
from angular-l10n.
Understand that pure pipes don't work, because the input parameter (lang) is updated by an event when the http request is completed.
How should I reflect the changes of the pure pipes using locale.setCurrentLocale();?
I am not using OnPush change detection strategy*
from angular-l10n.
@robisim74 Your change is working fine :-)
You can include this change in the next release.
from angular-l10n.
@skyfremen You have to extend the Locale
superclass in your components: it provides the subscriptions to update the parameters. If you have problems, please open a new issue
from angular-l10n.
any idea when you will release this change ?
from angular-l10n.
New minor version is out.
from angular-l10n.
@FabienDehopre I'm closing this issue. If you need, open a new issue. Greetings
from angular-l10n.
Hi, just a question: Would it be possible to get the same behaviour by using both the @Language
decorator and @input
on the lang: string property?
from angular-l10n.
Hi @MaciejWierzchowski, did you try it?
from angular-l10n.
Related Issues (20)
- 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
- Allow for template elements inside of params HOT 4
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.