]> Untitled Git - lemmy-ui.git/commitdiff
Extract date fns setup
authorSleeplessOne1917 <abias1122@gmail.com>
Fri, 23 Jun 2023 14:10:41 +0000 (10:10 -0400)
committerSleeplessOne1917 <abias1122@gmail.com>
Fri, 23 Jun 2023 14:10:41 +0000 (10:10 -0400)
src/client/index.tsx
src/server/index.tsx
src/shared/utils/app/index.ts
src/shared/utils/app/setup-date-fns.ts [new file with mode: 0644]

index 44d39d0b5eb3acc732c6080c68d90a0d8d31786d..1b7dde85fbfdf0e041bf100d14e68029e7394f3c 100644 (file)
@@ -1,9 +1,8 @@
-import { initializeSite } from "@utils/app";
-import setDefaultOptions from "date-fns/setDefaultOptions";
+import { initializeSite, setupI18Next as setupDateFns } from "@utils/app";
 import { hydrate } from "inferno-hydrate";
 import { Router } from "inferno-router";
 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/dropdown";
@@ -11,17 +10,7 @@ import "bootstrap/js/dist/dropdown";
 async function startClient() {
   initializeSite(window.isoData.site_res);
 
-  const lang = I18NextService.i18n.language;
-  const locale = (
-    await import(
-      /* webpackExclude: /\.js\.flow$/ */
-      `date-fns/locale/${lang}`
-    )
-  ).default;
-
-  setDefaultOptions({
-    locale,
-  });
+  await setupDateFns();
 
   const wrapper = (
     <Router history={HistoryService.history}>
index aecd78bb76e78153955221ae48df875d8a6ba743..8135e6507cb1bd98dbe702c067fa85b13c8eb22a 100644 (file)
@@ -1,8 +1,7 @@
-import setDefaultOptions from "date-fns/setDefaultOptions";
+import { setupI18Next as setupDateFns } from "@utils/app";
 import express from "express";
 import path from "path";
 import process from "process";
-import { I18NextService } from "../shared/services";
 import CatchAllHandler from "./handlers/catch-all-handler";
 import ManifestHandler from "./handlers/manifest-handler";
 import RobotsHandler from "./handlers/robots-handler";
@@ -33,20 +32,11 @@ server.get("/css/themelist", ThemesListHandler);
 server.get("/*", CatchAllHandler);
 
 server.listen(Number(port), hostname, () => {
+  setupDateFns();
   console.log(`http://${hostname}:${port}`);
 });
 
-process.on("SIGINT", async () => {
-  const lang = I18NextService.i18n.language;
-  const locale = (
-    await import(
-      /* webpackExclude: /\.js\.flow$/ */
-      `date-fns/locale/${lang}`
-    )
-  ).default;
-  setDefaultOptions({
-    locale,
-  });
+process.on("SIGINT", () => {
   console.info("Interrupted");
   process.exit(0);
 });
index cdae267786be2bb37e40caa4146615dcd842f873..378ebb75b4e7c64299acccf09a2b2e9d467b9d7a 100644 (file)
@@ -46,6 +46,7 @@ import searchCommentTree from "./search-comment-tree";
 import selectableLanguages from "./selectable-languages";
 import setIsoData from "./set-iso-data";
 import setTheme from "./set-theme";
+import setupI18Next from "./setup-date-fns";
 import showAvatars from "./show-avatars";
 import showLocal from "./show-local";
 import showScores from "./show-scores";
@@ -102,6 +103,7 @@ export {
   selectableLanguages,
   setIsoData,
   setTheme,
+  setupI18Next,
   showAvatars,
   showLocal,
   showScores,
diff --git a/src/shared/utils/app/setup-date-fns.ts b/src/shared/utils/app/setup-date-fns.ts
new file mode 100644 (file)
index 0000000..fe95720
--- /dev/null
@@ -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,
+  });
+}