github / relative-time-element

Web component extensions to the standard <time> element.
https://github.github.io/relative-time-element/examples/
MIT License
3.57k stars 170 forks source link

Fix default value of `lang` #275

Closed silverwind closed 8 months ago

silverwind commented 8 months ago

As per MDN:

The default value of lang is unknown

I'm pretty sure the previous value default was actually invalid.

silverwind commented 8 months ago

Upon further investigation, I think MDN is in error. The "unknown" word only appears in old W3C specs, but as literal text:

The default value of this attribute is unknown

The WHATWG spec recommends the empty string as the default.

Its value must be a valid BCP 47 language tag, or the empty string. Setting the attribute to the empty string indicates that the primary language is unknown.

silverwind commented 8 months ago

On the other hand, API's like Intl.RelativeTimeFormat and Intl.DateTimeFormatOptions reject the empty string for their locales option, and it seems the best thing to pass to those APIs would be a empty array.

I have a feeling it's likely better to not touch this any further, lest we break those whacky Intl APIs.

keithamus commented 8 months ago

Yeah default was carefully chosen as I think it doesn't reject. In reality I think this is somewhat undefined behavior for this element as anywhere we expect it to be used should have at minimum a lang attribute on the HTML element.

silverwind commented 8 months ago

I think for lang being a HTML attribute, empty string makes most sense. Intl APIs like Intl.DateTimeFormat not accepting empty string is a interop issue, but it also raises the question whether a lang is also a locale or whether they are different concepts.

As far as I understand lang='' is equivalent to locales=[], both result in "current locale" behaviour.

I submitted https://github.com/mdn/content/pull/32604 to correct MDN.