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.

Add locale support for month name

See original GitHub issue

Are you submitting a bug report or a feature request?

Feature request

What is the current behavior?

Month names are english only and there is no way to change it since it’s using formatDate function from date-fns, which defaults to en-US if no locale is specified.

What is the expected behavior?

Should be able to pass a locale prop to the component and get months names according to it.

What’s your environment?

simple-react-calendar 1.9.4

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
franciscohanna92commented, Feb 20, 2020

Ok! I have not use date-fns that much, but I will go for the dynamic import solution and open a PR.

0reactions
irhamputracommented, Oct 18, 2021

this is a great idea what I was looking for but currently the PR is still open. otherwise I need to overwrite via MonthHeaderComponent props and copy-paste from the month_header.tsx and header_button.tsx also the PR code

don’t forget to import module from date-fns.

workaround:

// Header Button
const HeaderButton = ({ arrow, blockClassName, enabled, type, title, onClick }) => (
  <button
    className={cx(`${blockClassName}-header_button`, `is-${type}`, {
      'is-disabled': !enabled,
    })}
    type="button"
    disabled={!enabled}
    title={title}
    onClick={onClick}
  >
    {arrow}
  </button>
);

// Custom Month Header
const CustomMonthHeader = ({
  activeMonth,
  minDate,
  maxDate,
  blockClassName,
  headerNextArrow,
  headerNextTitle,
  headerPrevArrow,
  headerPrevTitle,
  onMonthChange,
}) => {
  const prevEnabled = minDate ? isBefore(startOfMonth(minDate), startOfMonth(activeMonth)) : true;
  const nextEnabled = maxDate ? isAfter(startOfMonth(maxDate), startOfMonth(activeMonth)) : true;

  const switchMonth = (offset) => {
    onMonthChange(addMonths(activeMonth, offset));
  };

  return (
    <div className={`${blockClassName}-month_header`}>
      <HeaderButton
        type="prev"
        arrow={headerPrevArrow}
        title={headerPrevTitle}
        enabled={prevEnabled}
        onClick={() => switchMonth(-1)}
        blockClassName={blockClassName}
      />
      <div className={`${blockClassName}-month_header_title`}>{format(activeMonth, 'MMMM yyyy', { locale: de })}</div>
      <HeaderButton
        type="next"
        arrow={headerNextArrow}
        title={headerNextTitle}
        enabled={nextEnabled}
        onClick={() => switchMonth(1)}
        blockClassName={blockClassName}
      />
    </div>
  );
};


// Root Calendar
const Calendar = ({ onSelectDate, selectedDate, children }) => {
  return (
      <ReactCalendar
        MonthHeaderComponent={(props) => <CustomMonthHeader {...props} />}
        onSelect={onSelectDate}
        selected={selectedDate}
        activeMonth={selectedDate}
        renderDay={(props) => (
          <CustomDay {...props} />
        )}
        renderDayOfWeek={(props) => <CustomDayOfWeek {...props} />}
      />
  );
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get localized month name using native JS - Stack Overflow
var objDate = new Date("10/11/2009"), locale = "en-us", month = objDate.toLocaleString(locale, { month: "long" });. But this only gets the month ...
Read more >
Getting localized month and day names in the browser
Here's a tip — you can use it to generate localized month and day names without the need for a language pack! This...
Read more >
How to insert the full month name into the subject line of an e ...
To show the full month name for the locale the service is using, change the Date format string under System Information from MM/DD/YYYY...
Read more >
1.16 MySQL Server Locale Support - MySQL :: Developer Zone
The locale indicated by the lc_time_names system variable controls the language used to display day and month names and abbreviations.
Read more >
Month names according to the language settings, not locale.
Month names according to the language settings, not locale. My charts are in English and I want the months displayed in English as...
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