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.

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

github_iconTop GitHub Comments

1reaction
sly7-7commented, Dec 6, 2019

also, cc/ @marcoow, just for information

0reactions
richard-vineycommented, May 29, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

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