Skip to content

Conversation

@josh
Copy link
Contributor

@josh josh commented Apr 12, 2019

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 team April 12, 2019 22:38
@josh
Copy link
Contributor Author

josh commented Apr 12, 2019

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

@koddsson
Copy link
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
Contributor

mislav commented Apr 15, 2019

  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
Contributor

should we attempt to read the default locale from the document

navigator.language can be used

@josh josh force-pushed the intl-relativetimeformat branch 7 times, most recently from 817c563 to 2f3e550 Compare May 13, 2019 21:41
@josh
Copy link
Contributor Author

josh commented May 13, 2019

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

Copy link
Contributor

@koddsson koddsson left a comment

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.

Copy link
Contributor

@dgraham dgraham left a comment

Choose a reason for hiding this comment

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

😎

@josh
Copy link
Contributor Author

josh commented May 15, 2019

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

try {
// eslint-disable-next-line flowtype/no-flow-fix-me-comments
// $FlowFixMe: missing RelativeTimeFormat type
format = new Intl.RelativeTimeFormat(undefined, options)
Copy link
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
Contributor Author

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
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 josh force-pushed the intl-relativetimeformat branch from 2f3e550 to 5633266 Compare May 15, 2019 21:26
@josh
Copy link
Contributor Author

josh commented May 15, 2019

Decide how to handle "micro" formatter.

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

Copy link
Contributor

@muan muan left a comment

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
Copy link
Contributor Author

josh commented May 20, 2019

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

Sign up for free to 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.

7 participants