intl.locale property should be auto-tracked
See original GitHub issue- [ x] I am on the latest ember-intl version
- [ x] I have searched the issues of this repo and believe that this is not a duplicate
Environment
- Ember Version: 3.14
- Ember CLI Version: 3.14
- Ember Intl Version: 4.2.2
- Browser(s): Chrome
- Node Version:
Steps to Reproduce
Basically I try to remove the observers from my app, and in a helper, I have something like
import { observes } from '@ember-decorators/object';
import { inject as service } from '@ember/service';
import Helper from '@ember/component/helper';
export default class FormatListHelper extends Helper {
@service intl;
@observes('intl.locale')
localeChanged() {
this.recompute();
}
compute([elements]) {
if (elements.length === 1) {
return elements[0];
}
return `${elements.slice(0, -1).join(', ')} ${this.intl.t('and')} ${elements.slice(-1)}`;
}
}
after a discussion with @rwjblue I removed the observer, and if I understood well, just rewriting as this should just work
:
import { inject as service } from "@ember/service";
import Helper from "@ember/component/helper";
export default class FormatListHelper extends Helper {
@service intl;
compute([elements]) {
if (elements.length === 1) {
return elements[0];
}
return `${elements.slice(0, -1).join(", ")} ${this.intl.t(
"and"
)} ${elements.slice(-1)}`;
}
}
But for now, I have to access the intl.locale
property in order to make it work:
import { inject as service } from "@ember/service";
import Helper from "@ember/component/helper";
export default class FormatListHelper extends Helper {
@service intl;
compute([elements]) {
if (elements.length === 1) {
return elements[0];
}
this.intl.locale; // used to force auto-tracking of `ember-intl`'s locale computed
return `${elements.slice(0, -1).join(", ")} ${this.intl.t(
"and"
)} ${elements.slice(-1)}`;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Intl.Locale - JavaScript - MDN Web Docs
Chrome Edge
Locale Full support. Chrome74. Toggle history Full support. Edge79. Toggle hi...
Locale() constructor Full support. Chrome74. Toggle history Full support. Edge79. Toggle hi...
baseName...
Read more >Intl.Locale - TC39
The Locale constructor is a standard built-in property of the Intl object. ... which must be a Unicode locale extension sequence.
Read more >Property Locale does not exist on type of Intl? - Stack Overflow
const korean = new Intl.Locale('ko', { script: 'Kore', region: 'KR', ... You'll need to provide more context if you want help.
Read more >Intl - JavaScript - UDN Web Docs: MDN Backup
One property is supported by all language sensitive constructors and functions: The localeMatcher property, whose value must be a string " lookup "...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
also, cc/ @marcoow, just for information
I’ve opened a PR #1340 aiming to address this issue. If anyone is able to review and/or test it out that’d be great 👍.