More translations

This commit is contained in:
Blipz 2026-03-24 12:42:13 +01:00
parent 0b69c1882b
commit 7eeb1f76c3
11 changed files with 407 additions and 236 deletions

View file

@ -2,54 +2,54 @@ import i18next from "i18next";
import i18nextHTTPBackend from "i18next-http-backend";
import { isVowel } from "../utils";
window.locale = "fr";
function updateLabels() {
for (const label of document.querySelectorAll("[data-text]")) {
const translation = i18next.t(label.getAttribute("data-text"));
for (const label of document.querySelectorAll("[data-html]")) {
const translation = i18next.t(label.getAttribute("data-html") as string);
if (translation) label.innerHTML = translation;
}
for (const label of document.querySelectorAll("[data-text]")) {
const translation = i18next.t(label.getAttribute("data-text") as string);
if (translation) label.textContent = translation;
}
for (const tip of document.querySelectorAll("[data-tip]")) {
const translation = i18next.t(tip.getAttribute("data-tip"));
const translation = i18next.t(tip.getAttribute("data-tip") as string);
if (translation) tip.setAttribute("data-tip", translation);
}
}
window.i18n = i18next.use(i18nextHTTPBackend).init(
{
lng: window.locale,
//debug: true,
backend: {
loadPath: "locales/{{lng}}/lang.json",
function addFormatters() {
i18next.services.formatter?.add("gender", (value, lng, options) => {
if (lng !== "fr") return value;
else if (options.gender === "feminine") {
return value.endsWith("en") ? `${value}ne` : `${value}e`;
} else return value;
});
i18next.services.formatter?.add("of", (value, lng) => {
if (lng !== "fr") return value;
else if (isVowel(value[0].toLowerCase())) return `d'${value}`;
else return `de ${value}`;
});
i18next.services.formatter?.add("the", (value, lng, options) => {
if (lng !== "fr") return value;
else if (isVowel(value[0].toLowerCase())) return `L'${value}`;
else if (options.gender === "feminine") return `La ${value}`;
else return `Le ${value}`;
});
}
window.initLocale = async () => {
await i18next.use(i18nextHTTPBackend).init(
{
lng: options.language,
backend: {
loadPath: "locales/{{lng}}/lang.json",
},
},
},
() => {
if (document.readyState === "complete") {
() => {
addFormatters();
updateLabels();
} else {
document.addEventListener("DOMContentLoaded", () => {
updateLabels();
});
}
},
);
i18next.services.formatter.add("gender", (value, lng, options) => {
if (lng !== "fr") return value;
else if (options.gender === "feminine") {
return value.endsWith("en") ? `${value}ne` : `${value}e`;
} else return value;
});
i18next.services.formatter.add("of", (value, lng, options) => {
if (lng !== "fr") return value;
else if (isVowel(value[0].toLowerCase())) return `d'${value}`;
else return `de ${value}`;
});
i18next.services.formatter.add("the", (value, lng, options) => {
if (lng !== "fr") return value;
else if (isVowel(value[0].toLowerCase())) return `L'${value}`;
else if (options.gender === "feminine") return `La ${value}`;
else return `Le ${value}`;
});
},
);
};

View file

@ -1,5 +1,6 @@
import Alea from "alea";
import { max } from "d3";
import i18next from "i18next";
import {
byId,
gauss,
@ -141,7 +142,10 @@ class ProvinceModule {
: Names.getState(Names.getCultureShort(c), c);
const formName = rw(form);
form[formName] += 10;
const fullName = `${name} ${formName}`;
const fullName = i18next.t("{{provinceName}} {{provinceForm}}", {
provinceName: name,
provinceForm: i18next.t(formName),
});
const color = getMixedColor(s.color!);
const kinship = nameByBurg ? 0.8 : 0.4;
const type = Burgs.getType(center, burg.port);
@ -321,7 +325,10 @@ class ProvinceModule {
return rw(this.forms["Wild"]);
})();
const fullName = `${name} ${formName}`;
const fullName = i18next.t("{{provinceName}} {{provinceForm}}", {
provinceName: name,
provinceForm: i18next.t(formName),
});
const dominion = colony
? P(0.95)

View file

@ -831,7 +831,7 @@ class StatesModule {
"Marches",
];
if (!state.formName) return state.name;
const stateGender = gender[window.locale]?.[state.formName];
const stateGender = gender[options.language as string]?.[state.formName];
if (!state.name && state.formName)
return i18next.t("The {{noun}}", {
noun: i18next.t(state.formName),