picker
picker copied to clipboard
generateConfig for date-fns throws error for some locales
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
useit_IT
as locale name; -
dealLocal()
converts it intoitIT
; -
generateConfig.getWeekFirstDay()
method tries to loaddate-fns
locale data with anitIT
key, but it does not exists and this leads toclone
constant to beundefined
.
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;
Same problem with ru_RU locale
Same problem with de, fr locale
Hi, guys. Could you help to send PR about this?
I created a pull request to fix this: https://github.com/react-component/picker/pull/289
@zombieJ are there any issues regarding spawnia's PR?
Is there any way we can finally fix this after 2 years? German is still not working like other languages too...
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 That is what I was asking for 🥲