Files
mdg-filius/packages/editor/src/i18n/i18n.tsx
T
julian.kiedaischandClaude Opus 5.5 dfd5ec03ce feat(editor): F4.6a simulation mode and a computer's desktop
Java's mode buttons start and stop the room, now in a worker of the
editor's page (LocalSimHost), with Java's speed slider. While the
simulation runs the design is locked as in Java: no palette, no sheet,
nothing moves, no undo. Cables that carry a frame light up in Java's
green, and a tap on a computer opens its desktop: Java's title, the
software installation first, then the installed programs in the order
of Java's list for the language, a taskbar with the network icon and
the network as the simulation runs it. The room sends that over a new
topic, node:<id>. Desktops stay over a return to the design and show
again at the next start. The programs' windows follow from F4.6b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 13:41:41 +00:00

35 lines
1.5 KiB
TypeScript

// The editor's visible texts, German and English (plan §7.5): English keys,
// the words in i18n/{de,en}.json — where Java FILIUS has a word for a thing,
// Java's (MessagesBundle), so that the terms on worksheets fit. The language
// comes from the dashboard over the bridge.
import { createContext, useContext, type ReactNode } from 'react';
import de from './de.json';
import en from './en.json';
export type Language = 'de' | 'en';
export const CATALOGS: Readonly<Record<Language, Readonly<Record<string, string>>>> = { de, en };
export type Translate = (key: string, values?: Readonly<Record<string, string | number>>) => string;
/** The text of a key in a language, its {placeholders} filled; the key itself where the catalog has none. */
export function translate(language: Language, key: string, values: Readonly<Record<string, string | number>> = {}): string {
const text = CATALOGS[language][key] ?? key;
return text.replace(/\{(\w+)\}/g, (whole, name: string) => (name in values ? String(values[name]) : whole));
}
const LanguageContext = createContext<Language>('de');
export function LanguageProvider({ language, children }: { readonly language: Language; readonly children: ReactNode }) {
return <LanguageContext.Provider value={language}>{children}</LanguageContext.Provider>;
}
export function useLanguage(): Language {
return useContext(LanguageContext);
}
export function useTranslate(): Translate {
const language = useContext(LanguageContext);
return (key, values) => translate(language, key, values);
}