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

generateConfig for date-fns throws error for some locales #147

Closed
StefanoMagrassi opened this issue Sep 24, 2020 · 8 comments · Fixed by #763
Closed

generateConfig for date-fns throws error for some locales #147

StefanoMagrassi opened this issue Sep 24, 2020 · 8 comments · Fixed by #763

Comments

@StefanoMagrassi
Copy link

The generateConfig methods use dealLocal() function to get date-fns specific locale data for the provided language, but the implementation fails in some cases because rc-picker locales names do not exactly match with date-fns ones.

For example Italian:

  • rc-picker use it_IT as locale name;
  • dealLocal() converts it into itIT;
  • generateConfig.getWeekFirstDay() method tries to load date-fns locale data with an itIT key, but it does not exists and this leads to clone constant to be undefined.

The only solution is to replace the current dealLocal() implementation with a static map of locales names and prevent errors with a default value:

const DEFAULT_LOCALE = 'enUS';

const LOCALES_MAP = {
  'en_US': 'enUS',
  'it_IT': 'it',
  'es_ES': 'es',

  // and so on...
}

const dealLocal = (str: string): string => LOCALES_MAP[str] || DEFAULT_LOCALE;
@stepanzin
Copy link

Same problem with ru_RU locale

@Roguehp98
Copy link

Same problem with de, fr locale

@zombieJ
Copy link
Member

zombieJ commented Oct 19, 2020

Hi, guys. Could you help to send PR about this?

@spawnia
Copy link

spawnia commented Aug 27, 2021

I created a pull request to fix this: #289

@Saarnaki
Copy link

@zombieJ are there any issues regarding spawnia's PR?

@dingram94
Copy link

Is there any way we can finally fix this after 2 years? German is still not working like other languages too...

@spawnia
Copy link

spawnia commented Sep 22, 2023

Is there any way we can finally fix this after 2 years? German is still not working like other languages too...

Yup, merging #289 or implementing #289 (comment) would do it.

@dingram94
Copy link

@spawnia That is what I was asking for 🥲

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