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: allow setting calendar for i18n date formatting #6430

Merged
merged 4 commits into from
Apr 8, 2022

Conversation

Josh-Cena
Copy link
Collaborator

Motivation

Close #5440

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

None...yet

@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Jan 21, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 21, 2022
@Josh-Cena Josh-Cena marked this pull request as draft January 21, 2022 14:38
@Josh-Cena
Copy link
Collaborator Author

Let me think about it first... 🤔 We probably want to allow something like dateFormat: 'en-GB' as well to solve the need for DD/MM/YYYY

@netlify
Copy link

netlify bot commented Jan 21, 2022

[V2]

Name Link
🔨 Latest commit 0084e71
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/62503fa80a437f00082aed00
😎 Deploy Preview https://deploy-preview-6430--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Jan 21, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 55
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

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

@github-actions
Copy link

github-actions bot commented Jan 21, 2022

Size Change: +261 B (0%)

Total Size: 806 kB

Filename Size Change
website/build/assets/css/styles.********.css 105 kB +100 B (0%)
website/build/assets/js/main.********.js 612 kB +161 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/index.html 38.6 kB

compressed-size-action

@slorber
Copy link
Collaborator

slorber commented Jan 21, 2022

Let me think about it first... 🤔 We probably want to allow something like dateFormat: 'en-GB' as well to solve the need for DD/MM/YYYY

I don't know, that API would look weird to me and maybe too specific?

What are we trying to solve in the first place? I don't remember precisely

Are there any 'en-GB' users that do not want to format dates as DD/MM/YYYY?

If some user wants to use locale key en (or anything else) and still format dates as en-GB, maybe the solution would be to consider the key is not BPC47, and allow them to provide the BCP47 locale as attribute?

const i18n = {
  defaultLocale: "en",
  locales: ["en"],
  localeConfigs: {
    en: {
      localeCode: "en-GB"
    }
  }
};

@Josh-Cena
Copy link
Collaborator Author

Yes, maybe we want to merge this with htmlLang? i.e. use a short code for the base URL and the FS path, but the full BPC47 code for everything else in the code?

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

We can probably add this implementation for now, looks good enough 👍

@@ -24,6 +24,8 @@ export function getDefaultLocaleConfig(locale: string): I18nLocaleConfig {
label: getDefaultLocaleLabel(locale),
direction: getLangDir(locale),
htmlLang: locale,
// If the locale name includes -u-ca-xxx the calendar will be defined
Copy link
Collaborator

@slorber slorber Apr 8, 2022

Choose a reason for hiding this comment

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

maybe add a test case for this? Using something like ar-u-ca-islamicc ?

and a test case for an invalid locale, ensuring it falls back and fail-safe instead of crashing

Copy link
Collaborator Author

@Josh-Cena Josh-Cena Apr 8, 2022

Choose a reason for hiding this comment

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

We use new Intl.DisplayNames to construct the label, which is gonna crash on terribly malformed locale names anyways. new Intl.Locale is more resilient than new Intl.DisplayNames

Copy link
Collaborator

Choose a reason for hiding this comment

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

This currently works fine: yarn start:website --locale "My-weird-locale"

But anything more fancy will crash: yarn start:website --locale "My weird locale"

But ok we can implement that later, considering we don't have anything setup to accept properly an invalid locale name

@Josh-Cena Josh-Cena marked this pull request as ready for review April 8, 2022 14:04
@Josh-Cena Josh-Cena requested a review from slorber April 8, 2022 14:05
@Josh-Cena Josh-Cena merged commit 7941a46 into main Apr 8, 2022
@Josh-Cena Josh-Cena deleted the jc/i18n-calendar branch April 8, 2022 14:34
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.

i18n: allow to provide DateTimeFormat calendar
3 participants