Skip to content

Use Intl.RelativeTimeFormat - #104

Merged
josh merged 1 commit into
masterfrom
intl-relativetimeformat
May 20, 2019
Merged

Use Intl.RelativeTimeFormat#104
josh merged 1 commit into
masterfrom
intl-relativetimeformat

Conversation

@josh

@joshjosh commented Apr 12, 2019

Copy link
Copy Markdown
Contributor

Aims to implement #98.

To-do

  • Feature detect Intl.RelativeTimeFormat.
  • Decide how to handle "micro" formatter.
  • Fix tests.
  • Implement locale attribute

@josh
josh requested a review from a teamApril 12, 2019 22:38
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js Outdated
Comment threadsrc/relative-time.js
@josh

josh commented Apr 12, 2019

Copy link
Copy Markdown
ContributorAuthor

doh, @koddsson did you already start working on this? (#103)

@koddsson

Copy link
Copy Markdown
Contributor

@josh Nah I just started exploring and noticed that some tests for special cases that would break when we'd start using RelativeTimeFormat so I added those 😸

@mislav

Copy link
Copy Markdown
Contributor
  1. Is there going to be a locale attribute so that users may pass a locale specifier other than "en" down to Intl?
  2. If there isn't a locale attribute, should we attempt to read the default locale from the document, e.g. from <html lang="...">? https://www.w3.org/International/questions/qa-html-language-declarations

@keithamus

Copy link
Copy Markdown
Contributor

should we attempt to read the default locale from the document

navigator.language can be used

@josh
joshforce-pushed the intl-relativetimeformat branch 7 times, most recently from 817c563 to 2f3e550CompareMay 13, 2019 21:41
@josh

josh commented May 13, 2019

Copy link
Copy Markdown
ContributorAuthor

Alright, got tests passing here. Could use some review please 😁

@koddssonkoddsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

@dgrahamdgraham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

Comment threadtest/relative-time.js Outdated
@josh

josh commented May 15, 2019

Copy link
Copy Markdown
ContributorAuthor

Would also love some feedback on the effect of this change for people who can speak more than English 😁

Comment threadsrc/utils.js
try {
// eslint-disable-next-line flowtype/no-flow-fix-me-comments
// $FlowFixMe: missing RelativeTimeFormat type
format = new Intl.RelativeTimeFormat(undefined, options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to pass en as the locale until we add a locale attribute to the custom element so it's configurable by the host app. That will prevent this text from appearing in the default locale for the browser with the rest of the text appearing in English.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm down to support that, though I was just stealing from our existing makeFormatter.

https://github.com/github/time-elements/blob/4e6f95a34fc897626e794ed78f0f45701043de67/src/utils.js#L102

Will that need to change as well? Should I do this in a separate PR? Starting to wonder how this change is going to ship. It might be a major version bump. So could bundle this and that locale change in one release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the runtime's default locale is hardcoded to en in browsers and this is different from the user's preferred language setting in the operating system. Anyway, since undefined is already working for DateTimeFormat, we can use it here too.

A major version release would be appropriate since this changes the text output slightly.

We could couple that with <relative-time locale="…"> if it's not too much work. The only weird thing is that the locale attribute would only apply to browsers with RelativeTimeFormat support. The older code path would still use the hardcoded English text.

@josh
joshforce-pushed the intl-relativetimeformat branch from 2f3e550 to 5633266CompareMay 15, 2019 21:26
@josh

josh commented May 15, 2019

Copy link
Copy Markdown
ContributorAuthor

Decide how to handle "micro" formatter.

Not sure what to do, or even if we have to deal with this.

@muanmuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also love some feedback on the effect of this change for people who can speak more than English 😁

Can confirmed that relative timestamps within the month all look pretty reasonable. 🙆 Not sure if there's anything specific I should look for.

@josh

josh commented May 20, 2019

Copy link
Copy Markdown
ContributorAuthor

Thanks! I'll move forward with merging this and open another PR attempt for the locale= attribute.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@josh@koddsson@mislav@keithamus@dgraham@muan