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

[BUG] - DateRangePicker shows error messages only in English #2993

Open
GasparAdragna opened this issue May 13, 2024 · 6 comments
Open

[BUG] - DateRangePicker shows error messages only in English #2993

GasparAdragna opened this issue May 13, 2024 · 6 comments

Comments

@GasparAdragna
Copy link

NextUI Version

2.3.6

Describe the bug

When using the new DateRangePicker component with the I18nProvider set to "es", the error messages appear in english.

image

    <I18nProvider locale="es">
      <DateRangePicker
        aria-label="Datepicker"
        className="rounded-full lg:w-3/12"
        classNames={{
          inputWrapper: "rounded-full",
        }}
        maxValue={parseDate(today)}
        onChange={handleChange}
        shouldForceLeadingZeros
        value={value}
        visibleMonths={2}
      />
    </I18nProvider>

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

  1. Use the component DateRangePicker with the I18nProvider set to "es"
  2. Force an error on the component. F.E: Select an end date that's before the start date
  3. The error "Start date must be before end date" should appear.

Expected behavior

I expect the errors to show on the locale previously set in the provider

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

Copy link

linear bot commented May 13, 2024

@wingkwong
Copy link
Member

wingkwong commented May 13, 2024

In NextUIProvider, you can set locale es-ES.

@GasparAdragna
Copy link
Author

In NextUIProvider, you can set locale es-ES.

Nope, that doesn’t work either

@wingkwong
Copy link
Member

@GasparAdragna can you help run the following on your browser console and share the result? I was digging the react-stately code and think they retrieve the locale from the browser language setting rather than the provider.

(typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US'

@GasparAdragna
Copy link
Author

@wingkwong

Thanks for the reply, here is the result from the console:
image

As you suggest, the language is being retrieved by the browser language. This is not the expected behaviour, at least for me. I think it should have precedence the language set on the provider.

How can we change this?

@wingkwong
Copy link
Member

The logic is actually from react-aria side after digging into the source code.

function getLocale() {
  // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
  // validation messages, which to not respect our provider's language.
  // @ts-ignore
  return (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US';
}

And I do see some people raised this issue on their repo and here are some replies from their members.

Those error messages are the browser's built-in validation messages, so they rely on the browser's set language, not the provider's locale. There isn't currently a browser API for customizing this behavior. You can pass in custom error messages as an alternative instead.

We use priority of user settings: OS is the most general, then the browser, then the specific application in the browser, and so forth. Every instance that is more specific wins, if it was the other way around, then there'd be no way to change the settings from what the OS provides, and we don't want that.

We should consult the globalization team on this. I believe they might have raised something similar in the past as well. Even if the language of the website content is in a particular language, users might expect dates and numbers to be formatted according to a different setting. navigator.language also only specifies language, not region, so these are slightly different things. I could see it both ways tbh.

Therefore, there is not much we could do at this moment. You may have a custom errorMessage as a workaround. I'll put this issue on hold first until they resolve the problem.

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

No branches or pull requests

2 participants