Add language to frontend settings & correct some translations

This commit is contained in:
Jelcoo
2025-11-13 15:25:12 +01:00
committed by Jamie Curnow
parent 2c6d614597
commit c2177abe39
3 changed files with 29 additions and 10 deletions

View File

@@ -2,14 +2,15 @@ import { createIntl, createIntlCache } from "react-intl";
import langDe from "./lang/de.json";
import langEn from "./lang/en.json";
import langEs from "./lang/es.json";
import langIt from "./lang/it.json";
import langJa from "./lang/ja.json";
import langList from "./lang/lang-list.json";
import langNl from "./lang/nl.json";
import langPl from "./lang/pl.json";
import langRu from "./lang/ru.json";
import langSk from "./lang/sk.json";
import langZh from "./lang/zh.json";
import langPl from "./lang/pl.json";
import langIt from "./lang/it.json";
import langVi from "./lang/vi.json";
import langZh from "./lang/zh.json";
// first item of each array should be the language code,
// not the country code
@@ -25,6 +26,7 @@ const localeOptions = [
["pl", "pl-PL"],
["it", "it-IT"],
["vi", "vi-VN"],
["nl", "nl-NL"],
];
const loadMessages = (locale?: string): typeof langList & typeof langEn => {
@@ -48,6 +50,8 @@ const loadMessages = (locale?: string): typeof langList & typeof langEn => {
return Object.assign({}, langList, langEn, langIt);
case "vi":
return Object.assign({}, langList, langEn, langVi);
case "nl":
return Object.assign({}, langList, langEn, langNl);
default:
return Object.assign({}, langList, langEn);
}
@@ -82,6 +86,9 @@ const getFlagCodeForLocale = (locale?: string) => {
case "vi":
case "vi-VN":
return "VN";
case "nl":
case "nl-NL":
return "NL";
default:
return "EN";
}
@@ -105,7 +112,10 @@ const getLocale = (short = false) => {
const cache = createIntlCache();
const initialMessages = loadMessages(getLocale());
let intl = createIntl({ locale: getLocale(), messages: initialMessages }, cache);
let intl = createIntl(
{ locale: getLocale(), messages: initialMessages },
cache,
);
const changeLocale = (locale: string): void => {
const messages = loadMessages(locale);
@@ -145,4 +155,12 @@ const T = ({
);
};
export { localeOptions, getFlagCodeForLocale, getLocale, createIntl, changeLocale, intl, T };
export {
localeOptions,
getFlagCodeForLocale,
getLocale,
createIntl,
changeLocale,
intl,
T,
};