mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 06:11:15 +00:00
Add fallback date-fns locale import
This commit is contained in:
parent
61255bf01a
commit
515f5f5af3
1 changed files with 23 additions and 7 deletions
|
@ -1,10 +1,12 @@
|
||||||
import setDefaultOptions from "date-fns/setDefaultOptions";
|
import setDefaultOptions from "date-fns/setDefaultOptions";
|
||||||
import { I18NextService } from "../../services";
|
import { I18NextService } from "../../services";
|
||||||
|
|
||||||
|
const EN_US = "en-US";
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
let lang = I18NextService.i18n.language;
|
let lang = I18NextService.i18n.language;
|
||||||
if (lang === "en") {
|
if (lang === "en") {
|
||||||
lang = "en-US";
|
lang = EN_US;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if lang and country are the same, then date-fns expects only the lang
|
// if lang and country are the same, then date-fns expects only the lang
|
||||||
|
@ -17,12 +19,26 @@ export default async function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const locale = (
|
let locale;
|
||||||
await import(
|
|
||||||
/* webpackExclude: /\.js\.flow$/ */
|
try {
|
||||||
`date-fns/locale/${lang}`
|
locale = (
|
||||||
)
|
await import(
|
||||||
).default;
|
/* webpackExclude: /\.js\.flow$/ */
|
||||||
|
`date-fns/locale/${lang}`
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
`Could not load locale ${lang} from date-fns, falling back to ${EN_US}`
|
||||||
|
);
|
||||||
|
locale = (
|
||||||
|
await import(
|
||||||
|
/* webpackExclude: /\.js\.flow$/ */
|
||||||
|
`date-fns/locale/${EN_US}`
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
}
|
||||||
setDefaultOptions({
|
setDefaultOptions({
|
||||||
locale,
|
locale,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue