diff options
| author | Raphael <mail@raphaelkabo.com> | 2025-05-28 18:00:35 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-28 18:00:35 +0100 | 
| commit | bde9b408342f56833cf0a514488365189083f312 (patch) | |
| tree | e20a4f074704a2f5ede5ebd05b4f4ad949cd8205 /src/lib | |
| parent | 69f75005303d634b9208c23068655385734f4d3a (diff) | |
| parent | fb85d79dd2333cd6e0982e5ee0fdc1070ff99889 (diff) | |
Merge pull request #198 from dinoue/feature/localization-again
Localization, again
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.ts | 27 | ||||
| -rw-r--r-- | src/lib/event.ts | 4 | ||||
| -rw-r--r-- | src/lib/middleware.ts | 2 | 
3 files changed, 19 insertions, 14 deletions
diff --git a/src/lib/config.ts b/src/lib/config.ts index 6642eef..b08fa31 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -3,6 +3,7 @@ import toml from "toml";  import { exitWithError } from "./process.js";  import { Response } from "express";  import { markdownToSanitizedHTML } from "../util/markdown.js"; +import i18next from "i18next";  interface StaticPage {      title: string; @@ -110,44 +111,44 @@ export const instanceRules = (): InstanceRule[] => {      rules.push(          config.general.show_public_event_list              ? { -                text: "Public events and groups are displayed on the homepage", +                text: i18next.t("config.instancerule.showpubliceventlist-true"),                  icon: "fas fa-eye",              }              : { -                text: "Events and groups can only be accessed by direct link", +                text: i18next.t("config.instancerule.showpubliceventlist-false"),                  icon: "fas fa-eye-slash",              },      );      rules.push(          config.general.creator_email_addresses?.length              ? { -                text: "Only specific people can create events and groups", +                text: i18next.t("config.instancerule.creatoremail-true"),                  icon: "fas fa-user-check",              }              : { -                text: "Anyone can create events and groups", +                text: i18next.t("config.instancerule.creatoremail-false"),                  icon: "fas fa-users",              },      );      rules.push(          config.general.delete_after_days > 0              ? { -                text: `Events are automatically deleted ${config.general.delete_after_days} days after they end`, +                text: i18next.t("config.instancerule.deleteafterdays-true", { days: config.general.delete_after_days } ),                  icon: "far fa-calendar-times",              }              : { -                text: "Events are permanent, and are never automatically deleted", +                text: i18next.t("config.instancerule.deleteafterdays-false"),                  icon: "far fa-calendar-check",              },      );      rules.push(          config.general.is_federated              ? { -                text: "This instance federates with other instances using ActivityPub", +                text: i18next.t("config.instancerule.isfederated-true"),                  icon: "fas fa-globe",              }              : { -                text: "This instance does not federate with other instances", +                text: i18next.t("config.instancerule.isfederated-false"),                  icon: "fas fa-globe",              },      ); @@ -156,13 +157,15 @@ export const instanceRules = (): InstanceRule[] => {  export const instanceDescription = (): string => {      const config = getConfig(); -    const defaultInstanceDescription = -        "**{{ siteName }}** is running on Gathio — a simple, federated, privacy-first event hosting platform."; +    const defaultInstanceDescription = markdownToSanitizedHTML( +        i18next.t("config.defaultinstancedesc", "Welcome to this Gathio instance!") +    );      let instanceDescription = defaultInstanceDescription; +    let instancedescfile = "./static/instance-description-" + i18next.language + ".md";      try { -        if (fs.existsSync("./static/instance-description.md")) { +        if (fs.existsSync(instancedescfile)) {              const fileBody = fs.readFileSync( -                "./static/instance-description.md", +                instancedescfile,                  "utf-8",              );              instanceDescription = markdownToSanitizedHTML(fileBody); diff --git a/src/lib/event.ts b/src/lib/event.ts index 334ddf6..bcb7cd9 100644 --- a/src/lib/event.ts +++ b/src/lib/event.ts @@ -1,3 +1,4 @@ +import i18next from "i18next";  import { IEventGroup } from "../models/EventGroup.js";  export interface EventListEvent { @@ -15,7 +16,8 @@ export const bucketEventsByMonth = (      acc: Record<string, any>[],      event: EventListEvent,  ) => { -    const month = event.startMoment.format("MMMM YYYY"); +    event.startMoment.locale(i18next.language); +    const month = event.startMoment.format(i18next.t("common.year-month-format" ));      const matchingBucket = acc.find((bucket) => bucket.title === month);      if (!matchingBucket) {          acc.push({ diff --git a/src/lib/middleware.ts b/src/lib/middleware.ts index 69fbe4e..be05c3f 100644 --- a/src/lib/middleware.ts +++ b/src/lib/middleware.ts @@ -62,7 +62,7 @@ export const getConfigMiddleware = (      if (process.env.CYPRESS === "true" && req.cookies?.cypressConfigOverride) {          console.log("Overriding config with Cypress config");          const override = JSON.parse(req.cookies.cypressConfigOverride); -        res.locals.config = deepMerge<GathioConfig>(config, override); +        res.locals.config = deepMerge(config, override);          return next();      }      res.locals.config = config;  | 
