From 62e0f966b83ecaa2c13b1588dd23bec499197f41 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Mon, 2 Feb 2026 14:21:23 +0000 Subject: [PATCH] Mail types are now localised --- scripts/generate-locales.js | 20 +++++++++++++++++ src/i18n/generatedLocales.ts | 22 +++++++++++++++++++ src/i18n/i18n.ts | 6 ++++- .../domains/components/MailTemplatesTab.tsx | 4 ++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/scripts/generate-locales.js b/scripts/generate-locales.js index 8a83f68..794620b 100644 --- a/scripts/generate-locales.js +++ b/scripts/generate-locales.js @@ -16,15 +16,35 @@ const locales = rawLocales.map((l) => l.replace("_", "-")); // Sort by locale code locales.sort((a, b) => a.localeCompare(b)); +// Base locales (no hyphen) +const baseLocales = locales.filter((l) => !l.includes("-")); + // Only region-specific locales (those with a hyphen) const availableLocales = locales.filter((l) => l.includes("-")); +// Fallback map: region -> base (and default to en) +const fallbackLng = locales.reduce((acc, locale) => { + if (locale.includes("-")) { + const base = locale.split("-")[0]; + if (baseLocales.includes(base)) { + acc[locale] = base === "en" ? ["en"] : [base, "en"]; + } else { + acc[locale] = ["en"]; + } + } + return acc; +}, {}); + // Generate TS file const ts = ` // AUTO-GENERATED FILE — DO NOT EDIT MANUALLY export const availableLocales = ${JSON.stringify(availableLocales, null, 2)} as const; +export const baseLocales = ${JSON.stringify(baseLocales, null, 2)} as const; + +export const fallbackLng = ${JSON.stringify(fallbackLng, null, 2)} as const; + export type Locale = typeof availableLocales[number]; `; diff --git a/src/i18n/generatedLocales.ts b/src/i18n/generatedLocales.ts index d874e7a..5fcd94c 100644 --- a/src/i18n/generatedLocales.ts +++ b/src/i18n/generatedLocales.ts @@ -8,4 +8,26 @@ export const availableLocales = [ "fr-FR" ] as const; +export const baseLocales = [ + "en", + "fr" +] as const; + +export const fallbackLng = { + "en-GB": [ + "en" + ], + "en-US": [ + "en" + ], + "fr-CA": [ + "fr", + "en" + ], + "fr-FR": [ + "fr", + "en" + ] +} as const; + export type Locale = typeof availableLocales[number]; diff --git a/src/i18n/i18n.ts b/src/i18n/i18n.ts index c653c24..69cea19 100644 --- a/src/i18n/i18n.ts +++ b/src/i18n/i18n.ts @@ -3,6 +3,7 @@ import i18n from "i18next"; import { initReactI18next } from "react-i18next"; import HttpBackend from "i18next-http-backend"; import { determineInitialLocale } from "../modules/frame/services/lanugageService"; +import { fallbackLng } from "./generatedLocales"; export const Namespaces = { Common: "common", @@ -16,7 +17,10 @@ i18n .use(initReactI18next) .init({ lng: determineInitialLocale(), - fallbackLng: "en", + fallbackLng: { + ...fallbackLng, + default: ["en"], + }, defaultNS: "common", interpolation: { escapeValue: false, diff --git a/src/modules/manager/domains/components/MailTemplatesTab.tsx b/src/modules/manager/domains/components/MailTemplatesTab.tsx index 74b4196..eef0d41 100644 --- a/src/modules/manager/domains/components/MailTemplatesTab.tsx +++ b/src/modules/manager/domains/components/MailTemplatesTab.tsx @@ -12,8 +12,8 @@ interface MailType { } const MailTemplatesTab: React.FC = () => { - const { t: tMail } = useTranslation(); - const [loaded, setLoaded] = useState(true); + const { t: tMail } = useTranslation(Namespaces.MailTypes); + const [loaded, setLoaded] = useState(false); const [currentMailType, setCurrentMailType] = useState(""); const [types, setTypes] = useState([]);