localization for ntfy and mail

This commit is contained in:
MDeeApp
2025-10-11 19:34:54 +02:00
parent 17e094e8ac
commit adc4cfbee8
25 changed files with 609 additions and 74 deletions

View File

@@ -0,0 +1,45 @@
import defaultCategories from "@shared/defaultCategories.json";
type DefaultCategory = {
key: string;
de: string;
en: string;
};
const DEFAULT_CATEGORY_DATA = defaultCategories as DefaultCategory[];
function normalize(input: string): string {
return input.trim().toLowerCase();
}
const translationsByNormalizedName = new Map<string, DefaultCategory>();
for (const category of DEFAULT_CATEGORY_DATA) {
translationsByNormalizedName.set(normalize(category.de), category);
translationsByNormalizedName.set(normalize(category.en), category);
}
export function getCanonicalDefaultCategoryName(input: string): string | null {
const normalized = normalize(input);
const match = translationsByNormalizedName.get(normalized);
return match ? match.de : null;
}
export function translateCategoryName(name: string | null | undefined, language: string): string {
if (!name) {
return "";
}
const normalized = normalize(name);
const match = translationsByNormalizedName.get(normalized);
if (!match) {
return name;
}
if (language.startsWith("de")) {
return match.de;
}
if (language.startsWith("en")) {
return match.en;
}
// For other languages we fall back to English to keep labels readable.
return match.en;
}