From: sunaurus Date: Fri, 30 Jun 2023 16:59:44 +0000 (+0300) Subject: Fix date-fns locale import failing for some locales X-Git-Url: http://these/git/ui/assets/%7Bthis.favIcon%7D?a=commitdiff_plain;h=ed1f208e47e17eaadba3008c4396aea820520662;p=lemmy-ui.git Fix date-fns locale import failing for some locales --- diff --git a/src/shared/utils/app/setup-date-fns.ts b/src/shared/utils/app/setup-date-fns.ts index fe95720..44f27ac 100644 --- a/src/shared/utils/app/setup-date-fns.ts +++ b/src/shared/utils/app/setup-date-fns.ts @@ -7,6 +7,16 @@ export default async function () { lang = "en-US"; } + // if lang and country are the same, then date-fns expects only the lang + // eg: instead of "fr-FR", we should import just "fr" + + if (lang.includes("-")) { + const parts = lang.split("-"); + if (parts[0] === parts[1].toLowerCase()) { + lang = parts[0]; + } + } + const locale = ( await import( /* webpackExclude: /\.js\.flow$/ */