Extract date fns setup

This commit is contained in:
SleeplessOne1917 2023-06-23 10:10:41 -04:00 committed by Jay Sitter
parent 309c36018b
commit 40c236eb9d
4 changed files with 27 additions and 27 deletions

View file

@ -1,9 +1,8 @@
import { initializeSite } from "@utils/app"; import { initializeSite, setupI18Next as setupDateFns } from "@utils/app";
import setDefaultOptions from "date-fns/setDefaultOptions";
import { hydrate } from "inferno-hydrate"; import { hydrate } from "inferno-hydrate";
import { Router } from "inferno-router"; import { Router } from "inferno-router";
import { App } from "../shared/components/app/app"; import { App } from "../shared/components/app/app";
import { HistoryService, I18NextService } from "../shared/services"; import { HistoryService } from "../shared/services";
import "bootstrap/js/dist/collapse"; import "bootstrap/js/dist/collapse";
import "bootstrap/js/dist/dropdown"; import "bootstrap/js/dist/dropdown";
@ -11,17 +10,7 @@ import "bootstrap/js/dist/dropdown";
async function startClient() { async function startClient() {
initializeSite(window.isoData.site_res); initializeSite(window.isoData.site_res);
const lang = I18NextService.i18n.language; await setupDateFns();
const locale = (
await import(
/* webpackExclude: /\.js\.flow$/ */
`date-fns/locale/${lang}`
)
).default;
setDefaultOptions({
locale,
});
const wrapper = ( const wrapper = (
<Router history={HistoryService.history}> <Router history={HistoryService.history}>

View file

@ -1,8 +1,7 @@
import setDefaultOptions from "date-fns/setDefaultOptions"; import { setupI18Next as setupDateFns } from "@utils/app";
import express from "express"; import express from "express";
import path from "path"; import path from "path";
import process from "process"; import process from "process";
import { I18NextService } from "../shared/services";
import CatchAllHandler from "./handlers/catch-all-handler"; import CatchAllHandler from "./handlers/catch-all-handler";
import ManifestHandler from "./handlers/manifest-handler"; import ManifestHandler from "./handlers/manifest-handler";
import RobotsHandler from "./handlers/robots-handler"; import RobotsHandler from "./handlers/robots-handler";
@ -33,20 +32,11 @@ server.get("/css/themelist", ThemesListHandler);
server.get("/*", CatchAllHandler); server.get("/*", CatchAllHandler);
server.listen(Number(port), hostname, () => { server.listen(Number(port), hostname, () => {
setupDateFns();
console.log(`http://${hostname}:${port}`); console.log(`http://${hostname}:${port}`);
}); });
process.on("SIGINT", async () => { process.on("SIGINT", () => {
const lang = I18NextService.i18n.language;
const locale = (
await import(
/* webpackExclude: /\.js\.flow$/ */
`date-fns/locale/${lang}`
)
).default;
setDefaultOptions({
locale,
});
console.info("Interrupted"); console.info("Interrupted");
process.exit(0); process.exit(0);
}); });

View file

@ -46,6 +46,7 @@ import searchCommentTree from "./search-comment-tree";
import selectableLanguages from "./selectable-languages"; import selectableLanguages from "./selectable-languages";
import setIsoData from "./set-iso-data"; import setIsoData from "./set-iso-data";
import setTheme from "./set-theme"; import setTheme from "./set-theme";
import setupI18Next from "./setup-date-fns";
import showAvatars from "./show-avatars"; import showAvatars from "./show-avatars";
import showLocal from "./show-local"; import showLocal from "./show-local";
import showScores from "./show-scores"; import showScores from "./show-scores";
@ -102,6 +103,7 @@ export {
selectableLanguages, selectableLanguages,
setIsoData, setIsoData,
setTheme, setTheme,
setupI18Next,
showAvatars, showAvatars,
showLocal, showLocal,
showScores, showScores,

View file

@ -0,0 +1,19 @@
import setDefaultOptions from "date-fns/setDefaultOptions";
import { I18NextService } from "../../services";
export default async function () {
let lang = I18NextService.i18n.language;
if (lang === "en") {
lang = "en-US";
}
const locale = (
await import(
/* webpackExclude: /\.js\.flow$/ */
`date-fns/locale/${lang}`
)
).default;
setDefaultOptions({
locale,
});
}