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

Changing locale doesn't change locale text for inline datepicker #1203

Closed
klis87 opened this issue Jan 10, 2018 · 8 comments
Closed

Changing locale doesn't change locale text for inline datepicker #1203

klis87 opened this issue Jan 10, 2018 · 8 comments
Labels

Comments

@klis87
Copy link

klis87 commented Jan 10, 2018

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.

@etienne-bondot
Copy link

Did you try to import the moment locale as import 'moment/locale/<your_locale>'; ?

@klis87
Copy link
Author

klis87 commented 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.

@cheton
Copy link

cheton commented Mar 2, 2018

Same to me with the following setup:

<DatePicker
    inline
    locale={locale}
/>

If I change the locale prop, it won't update current translation, unless I change the selected date with mouse click or update the "selected" prop.

@patfrat
Copy link

patfrat commented Mar 7, 2018

Same problem by my side, the locale text changes when choosing another date only !
It seems that the locale change is not listened by the DatePicker Component

@aleksandr-senichev
Copy link

aleksandr-senichev commented Aug 27, 2018

Same issue for inline calendar

@Dean177
Copy link

Dean177 commented Sep 14, 2018

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

<DatePicker
  inline={true}
  key={locale}
  locale={locale}
/>

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Sonamkhurana
Copy link

Has anyone resolved this issue?

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

No branches or pull requests

7 participants