StaticJsCMS / static-cms

A Git-based CMS for Static Site Generators
https://staticcms.org
MIT License
579 stars 52 forks source link

Setup AdapterDateFns with current locale #1081

Closed oliverpool closed 2 months ago

oliverpool commented 5 months ago

Currently the date picker always show AM/PM, which is unusual for non-english people.

Digging in the code, it seems that mui-x is using the en-US is locale is not set: https://github.com/mui/mui-x/blob/603e688d3a55740578dcd193e59063ce7bdab389/packages/x-date-pickers/src/AdapterDateFnsBase/AdapterDateFnsBase.ts#L224

  public is12HourCycleInCurrentLocale = () => {
    if (this.locale) {
      return /a/.test(this.locale.formatLong!.time({ width: 'short' }));
    }

    // By default, date-fns is using en-US locale with am/pm enabled
    return true;
  };

It would be nice with the locale setting could be set on date-fns: https://github.com/StaticJsCMS/static-cms/blob/9b26aff35bd00340f0e6013f744cdfc50db1e663/packages/core/src/widgets/datetime/DateTimeControl.tsx#L209

// with date-fns v2.x
import locales from 'date-fns/locale';
const current_locale = locales[config.locale] ?? null; // logic could be improved?

<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={current_locale}>

I would be ready to make a PR, however I don't know:

What do you think?