picker icon indicating copy to clipboard operation
picker copied to clipboard

generateConfig for date-fns throws error for some locales

Open StefanoMagrassi opened this issue 3 years ago • 5 comments

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;

StefanoMagrassi avatar Sep 24 '20 13:09 StefanoMagrassi

Same problem with ru_RU locale

stepanzin avatar Sep 25 '20 10:09 stepanzin

Same problem with de, fr locale

Roguehp98 avatar Oct 01 '20 18:10 Roguehp98

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

zombieJ avatar Oct 19 '20 11:10 zombieJ

I created a pull request to fix this: https://github.com/react-component/picker/pull/289

spawnia avatar Aug 27 '21 14:08 spawnia

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

Saarnaki avatar Dec 29 '21 15:12 Saarnaki

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

dingram94 avatar Sep 22 '23 10:09 dingram94

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

Yup, merging https://github.com/react-component/picker/pull/289 or implementing https://github.com/react-component/picker/pull/289#issuecomment-1063640635 would do it.

spawnia avatar Sep 22 '23 10:09 spawnia

@spawnia That is what I was asking for 🥲

dingram94 avatar Sep 22 '23 10:09 dingram94