Polish UI, harden company creation, and add error pages

This commit is contained in:
cesnimda
2026-03-23 19:34:29 +01:00
parent 8f5eab2fe4
commit fcafda6f52
38 changed files with 2293 additions and 1269 deletions
+9 -2
View File
@@ -1,14 +1,21 @@
import React, { createContext, useContext, useState } from "react";
import { translations, TranslationKey, UiLanguage } from "./translations";
type TranslationParams = Record<string, string | number>;
type Ctx = {
language: UiLanguage;
setLanguage: (l: UiLanguage) => void;
t: (key: TranslationKey) => string;
t: (key: TranslationKey, params?: TranslationParams) => string;
};
const I18nContext = createContext<Ctx | null>(null);
function interpolate(template: string, params?: TranslationParams) {
if (!params) return template;
return template.replace(/\{(\w+)\}/g, (_, key) => String(params[key] ?? `{${key}}`));
}
export function I18nProvider({ children }: { children: React.ReactNode }) {
const [language, setLanguageState] = useState<UiLanguage>(() => {
const raw = window.localStorage.getItem("uiLanguage");
@@ -20,7 +27,7 @@ export function I18nProvider({ children }: { children: React.ReactNode }) {
window.localStorage.setItem("uiLanguage", l);
};
const t = (key: TranslationKey) => translations[language][key] ?? translations.en[key];
const t = (key: TranslationKey, params?: TranslationParams) => interpolate(translations[language][key] ?? translations.en[key], params);
return <I18nContext.Provider value={{ language, setLanguage, t }}>{children}</I18nContext.Provider>;
}