Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Framework] Localize date strings in pages #252

Merged
merged 1 commit into from
May 3, 2018

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented May 3, 2018

Last modified dates and publication dates were always formatted in English. They should now be formatted according to the language of the page.

Under the hoods, the toLocaleDateString method gets used to format the date. Note browsers may only support a subset of locale settings in practice (and may for instance only support locale settings that are actually local to the user), so that mechanism may not always work.

In particular, JSDOM, used to generate all roadmap pages in batch, does not seem to support Chinese, so rules for Chinese are hardcoded if JSDOM is detected.

This commit is a fix for:
#213 (comment)

Last modified dates and publication dates were always formatted in English.
They should now be formatted according to the language of the page.

Under the hoods, the `toLocaleDateString` method gets used to format the date.
Note browsers may only support a subset of locale settings in practice (and
may for instance only support locale settings that are actually local to the
user), so that mechanism may not always work.

In particular, JSDOM, used to generate all roadmap pages in batch, does not
seem to support Chinese, so rules for Chinese are hardcoded if JSDOM is
detected.

This commit is a fix for:
w3c#213 (comment)
@xfq
Copy link
Member

xfq commented May 3, 2018

LGTM.

We can also switch to intl (which implements ECMA-402) if we would like to support more languages/locales. Merging.

@xfq xfq merged commit a4609da into w3c:master May 3, 2018
@xfq xfq deleted the framework-localizedates branch May 3, 2018 11:54
*/
const formatMonthAndYearDate = function (date, lang) {
if (((lang === 'zh') || lang.startsWith('zh-')) &&
window._runScripts && window._virtualConsole && (window.name === 'nodejs')) {
Copy link

Choose a reason for hiding this comment

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

I figured I should note that window.name === 'nodejs' is not supported as a way to detect jsdom, and is planned for removal in the next major version: jsdom/jsdom#2069

While no changes are planned to them at the moment, the properties starting with _ are also not part of the public API and could change in any version. The recommended way to detect jsdom is to inspect the user agent string instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Duly noted, and thanks for chiming in, @Zirro! Now tracked in #255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants