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

feat(v2): infer default i18n locale config from locale code #4449

Merged
merged 3 commits into from
Mar 18, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Mar 17, 2021

Motivation

In most situations, we shouldn't need to provide a i18n.localeConfigs because the locale direction and locale labels can generally be inferred from the locale itself, considering it is compliant with BCP 47 locales and Node 14 Intl API is able to get language labels.

Also made it possible to run yarn start --locale fa even if fa is not in the config: it will just print a warning instead of throwing.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

tests and v2 site

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Mar 17, 2021
@slorber slorber requested a review from lex111 as a code owner March 17, 2021 18:53
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 17, 2021
@slorber
Copy link
Collaborator Author

slorber commented Mar 17, 2021

@longlho can you help review this please?

return new Intl.DisplayNames([locale], {type: 'language'}).of(locale);
}
return locale;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@longlho particularly not sure of this part.

It seems Intl.DisplayNames does not exist on Node 13. Can you help me figure out where to check the NodeJS support of Intl apis?

Also not sure how to make TS happy

Copy link
Contributor

Choose a reason for hiding this comment

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

Intl.DisplayNames is ES2021 which is not yet published so it won't be in TS native type def for a while

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please ignore the rest of the diff, this is mostly for this code that I pinged you 😆

Thanks, didn't know.
So is it safe to consider this API is available in Node14? Not sure where to check that exactly

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah as long as MDN says it is then you're good. I wouldn't check for node version but rather check for if (!!Intl.DisplayNames) or something like that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, will do that.

It seems I can get this kind of infos on the v8 site directly: https://v8.dev/features/intl-displaynames

Seems supported since Node 14+, so I think we'd rather recommend using Node 14 and not just node >= 13 for Docusaurus i18n, as it's also a LTS

Thanks for the review

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just for curiosity, why is this stage 4 in 2020 and not in ES2020?

Apparently, it's not even ES2021 but 2022?
https://tc39.es/ecma402/#intl-displaynames-objects

@netlify
Copy link

netlify bot commented Mar 17, 2021

[V1] Deploy preview success

Built with commit 3e693e2

https://deploy-preview-4449--docusaurus-1.netlify.app

@netlify
Copy link

netlify bot commented Mar 17, 2021

Deploy preview for docusaurus-2 ready!

Built with commit 3e693e2

https://deploy-preview-4449--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Mar 17, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 91
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4449--docusaurus-2.netlify.app/classic/

@github-actions
Copy link

github-actions bot commented Mar 17, 2021

Size Change: +195 B (0%)

Total Size: 598 kB

Filename Size Change
website/build/assets/js/main.********.js 424 kB -77 B (0%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 61 kB +136 B (0%)
website/build/index.html 25.9 kB +136 B (+1%)
ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.3 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B

compressed-size-action

@netlify
Copy link

netlify bot commented Mar 17, 2021

[V1] Deploy preview success

Built with commit 2e1cc49

https://deploy-preview-4449--docusaurus-1.netlify.app

@netlify
Copy link

netlify bot commented Mar 17, 2021

Deploy preview for docusaurus-2 ready!

Built with commit 2e1cc49

https://deploy-preview-4449--docusaurus-2.netlify.app

@longlho
Copy link
Contributor

longlho commented Mar 17, 2021

@slorber can you explain the use case a bit more? default locale has a lot of implication in terms of negotiation (e.g if I support en-US and you ask for en-GB technically I can fallback, but not the other way around).

@slorber
Copy link
Collaborator Author

slorber commented Mar 17, 2021

@longlho default locale is just the one we use in priority if no locale is provided by the cli - - locale option, we don't have a fallback system for now

@slorber slorber changed the title feat(v2): default locale config feat(v2): infer default i18n locale config from locale code Mar 18, 2021
@slorber slorber merged commit 806fdba into master Mar 18, 2021
@slorber slorber deleted the slorber/default-locale-config branch August 17, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants