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.

Changing locale doesn't change locale text for inline datepicker

See original GitHub issue

I have a following component:

import React from 'react';
import VendorDatePicker from 'react-datepicker';
import { connect } from 'react-redux';

import { currentLanguageSelector } from 'stores/routes/selectors';

const mapStateToProps = state => ({
  currentLanguage: currentLanguageSelector(state),
});

const DatePicker = ({ currentLanguage, ...props }) => (
  <VendorDatePicker
    inline
    locale={currentLanguage}
    {...props}
  />
);

export default connect(mapStateToProps)(DatePicker);

Expected behavior

When in redux currentLanguage is changed, new locale prop is passed to DatePicker and locale texts should be translated to a new language.

Actual behavior

When in redux currentLanguage is changed, new locale prop is passed to DatePicker and locale texts is not translated to a new language. Only for example after DatePicker internal state like selected value is changed, text is translated.

Steps to reproduce

Use DatePicker component in inline version and pass dynamic locale. After changing it, you will notice that datepicker text remains the same.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

3reactions
klis87commented, Jan 25, 2018

Actually moment imports all locales as the default, and I import only en-gb and pl by webpack config: new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en-gb|pl/),

Locale works fine, it is imported and translates everything correctly, the only problem is that DatePicker doesnt rerender when ONLY locale prop is changed - after any other prop like selected is changed, suddenly new locale is picked up. This issue is only for inline calendars.

1reaction
Dean177commented, Sep 14, 2018

A bit of a hack, but this is a quick fix:

<DatePicker
  inline={true}
  key={locale}
  locale={locale}
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change language for bootstrap DateTimePicker
i think you have to set it in the options: $(".form_datetime").datetimepicker({ isRTL: false, format: 'dd.mm.yyyy hh:ii', autoclose:true, language: 'ru' });.
Read more >
Locale filter in conjunction with new datepicker localization
I was able to successfully change the datepicker's strings to a different locale for a single page using the switch_to_locale() function ...
Read more >
Options - getdatepicker.com
options(). Returns the components current options object. Note that the changing the values of the returned object does not change the components actual ......
Read more >
Datepicker Widget - jQuery UI API Documentation
The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and...
Read more >
ion-datetime
For example, if locale is set to en-US , then ion-datetime will use a 12 hour cycle. ... For example, setting date-time will...
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