import { getSafeLocalStorage } from "../../local-storage.ts"; import { en } from "../locales/en.ts"; import {
DEFAULT_LOCALE,
SUPPORTED_LOCALES,
isSupportedLocale,
loadLazyLocaleTranslation,
resolveNavigatorLocale,
} from "./registry.ts"; import type { Locale, TranslationMap } from "./types.ts";
type Subscriber = (locale: Locale) => void;
export { SUPPORTED_LOCALES, isSupportedLocale };
class I18nManager { private locale: Locale = DEFAULT_LOCALE; private translations: Partial<Record<Locale, TranslationMap>> = { [DEFAULT_LOCALE]: en }; private subscribers: Set<Subscriber> = new Set();
public t(key: string, params?: Record<string, string>): string { const keys = key.split(".");
let value: unknown = this.translations[this.locale] || this.translations[DEFAULT_LOCALE];
for (const k of keys) { if (value && typeof value === "object") {
value = (value as Record<string, unknown>)[k];
} else {
value = undefined; break;
}
}
// Fallback to English. if (value === undefined && this.locale !== DEFAULT_LOCALE) {
value = this.translations[DEFAULT_LOCALE]; for (const k of keys) { if (value && typeof value === "object") {
value = (value as Record<string, unknown>)[k];
} else {
value = undefined; break;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.