Mail types are now localised
This commit is contained in:
parent
e936870ebc
commit
62e0f966b8
@ -16,15 +16,35 @@ const locales = rawLocales.map((l) => l.replace("_", "-"));
|
|||||||
// Sort by locale code
|
// Sort by locale code
|
||||||
locales.sort((a, b) => a.localeCompare(b));
|
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)
|
// Only region-specific locales (those with a hyphen)
|
||||||
const availableLocales = locales.filter((l) => l.includes("-"));
|
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
|
// Generate TS file
|
||||||
const ts = `
|
const ts = `
|
||||||
// AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
|
// AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
|
||||||
|
|
||||||
export const availableLocales = ${JSON.stringify(availableLocales, null, 2)} as const;
|
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];
|
export type Locale = typeof availableLocales[number];
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@ -8,4 +8,26 @@ export const availableLocales = [
|
|||||||
"fr-FR"
|
"fr-FR"
|
||||||
] as const;
|
] 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];
|
export type Locale = typeof availableLocales[number];
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import i18n from "i18next";
|
|||||||
import { initReactI18next } from "react-i18next";
|
import { initReactI18next } from "react-i18next";
|
||||||
import HttpBackend from "i18next-http-backend";
|
import HttpBackend from "i18next-http-backend";
|
||||||
import { determineInitialLocale } from "../modules/frame/services/lanugageService";
|
import { determineInitialLocale } from "../modules/frame/services/lanugageService";
|
||||||
|
import { fallbackLng } from "./generatedLocales";
|
||||||
|
|
||||||
export const Namespaces = {
|
export const Namespaces = {
|
||||||
Common: "common",
|
Common: "common",
|
||||||
@ -16,7 +17,10 @@ i18n
|
|||||||
.use(initReactI18next)
|
.use(initReactI18next)
|
||||||
.init({
|
.init({
|
||||||
lng: determineInitialLocale(),
|
lng: determineInitialLocale(),
|
||||||
fallbackLng: "en",
|
fallbackLng: {
|
||||||
|
...fallbackLng,
|
||||||
|
default: ["en"],
|
||||||
|
},
|
||||||
defaultNS: "common",
|
defaultNS: "common",
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false,
|
escapeValue: false,
|
||||||
|
|||||||
@ -12,8 +12,8 @@ interface MailType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MailTemplatesTab: React.FC = () => {
|
const MailTemplatesTab: React.FC = () => {
|
||||||
const { t: tMail } = useTranslation<typeof Namespaces.MailTypes>();
|
const { t: tMail } = useTranslation(Namespaces.MailTypes);
|
||||||
const [loaded, setLoaded] = useState(true);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const [currentMailType, setCurrentMailType] = useState("");
|
const [currentMailType, setCurrentMailType] = useState("");
|
||||||
const [types, setTypes] = useState<MailType[]>([]);
|
const [types, setTypes] = useState<MailType[]>([]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user