diff --git a/src/index.js b/src/index.js index 8c919b0d8..c965dd004 100644 --- a/src/index.js +++ b/src/index.js @@ -12,12 +12,17 @@ const parseLocale = (preset, object, isLocal) => { let l if (!preset) return L if (typeof preset === 'string') { - if (Ls[preset]) { - l = preset + const presetLower = preset.toLowerCase() + if (Ls[presetLower]) { + l = presetLower } if (object) { - Ls[preset] = object - l = preset + Ls[presetLower] = object + l = presetLower + } + const presetSplit = preset.split('-') + if (!l && presetSplit.length > 1) { + return parseLocale(presetSplit[0]) } } else { const { name } = preset diff --git a/test/plugin/localizedFormat.test.js b/test/plugin/localizedFormat.test.js index 1c7a89e14..da5b219e0 100644 --- a/test/plugin/localizedFormat.test.js +++ b/test/plugin/localizedFormat.test.js @@ -96,6 +96,16 @@ it('Uses the localized lowercase formats if defined', () => { ['l', 'll', 'lll', 'llll'].forEach(option => expect(znDate.format(option)).toBe(znDate.format(znCn.formats[option]))) }) +it('Uses fallback to xx if xx-yy not available', () => { + expect(dayjs('2019-02-01').locale('en-yy').format('MMMM')) + .toBe('February') +}) + +it('Uses xx-yy if xx-YY is provided', () => { + expect(dayjs('2019-02-01').locale('es-US').format('MMMM')) + .toBe('febrero') +}) + it('Uses the localized uppercase formats as a base for lowercase formats, if not defined', () => { const date = new Date() const spanishDate = dayjs(date, { locale: es });