question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow setting default locale for DatePicker

See original GitHub issue

Summary

Is it possible to set default locale for DatePicker? Then we don’t need to pass locale to each DatePicker component.

Justification

No.

Desired UX and success metrics

Probably we can add a function to set default locale?

import { DatePicker } from "carbon-components-react";

DatePicker.setDefaultLocale("zh_tw");

“Must have” functionality

Set default locale for DatePicker

Specific timeline issues / requests

We have a GVT defect in our backlog. It’s up to this ticket to decide whether we should directly fix this defect by adding locale prop to each DatePicker.

Available extra resources

What resources do you have to assist this effort?

I guess we probably can discuss the better way to do this. If needed, I can create a PR for it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tay1orjonescommented, Sep 9, 2021

Hi @fred104 sorry for the delay in responding. If I understand correctly, you’d like to set a new default locale for all DatePickers in your application.

If this is the case, I’d recommend creating a lightweight wrapper around DatePicker that would set the locale to your preferred locale. You can then reuse this wrapper throughout your application in place of DatePicker. Something like this might work:

import { DatePicker as CarbonDatePicker } from "carbon-components-react";

export function DatePicker(props) {
  return (
    // `fr` is used here, but can be whatever locale you'd like the new "default" to be
    <CarbonDatePicker locale={props?.locale || "fr"} {...props}>
      {props?.children}
    </CarbonDatePicker>
  );
};

Here’s a quick codesandbox example I cooked up.

1reaction
jnm2377commented, Sep 9, 2021

Closing this issue, since this is not a bug and no enhancement is needed. For anyone else wanting to do a similar thing, we’ve provided the recommended solution above for setting the same prop value to more than one component without having to explicitly add the prop to each component instance (see https://github.com/carbon-design-system/carbon/issues/9248#issuecomment-916371174)

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Set default Locale to DatePicker and TimePicker
I want to either change localization of DatePicker and TimePicker to English all the time, Or to change it to Arabic when the...
Read more >
Locale support(DatePicker) needs better locale support
Summary There needs to be more supported locales, and better logic in determining which locale to use. This is a development request.
Read more >
DatePicker
Default locale is en , to change this follow dayjs localization guide: // First import locale data. import 'dayjs/locale/ru';. Then set locale prop...
Read more >
Date and Time pickers - Localization
Date and Time pickers allow to support users from different locales, with formatting, RTL, and localized strings. The default locale of MUI is...
Read more >
How to set a Date picker language format instead of using local
I would like all my Date pickers to be displayed in english language i.e Jun-2020 irrespective of the user's local language. Formula on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found