refactor: consolidate English translations (#6640)

This commit is contained in:
Thomas authored and GitHub committed 2026-08-21 19:00:27 +02:00
1 parent 81aa704537
commit 9e14a07e64
449 files changed
+3515 -3922

No files matched your search

+31 -7
View File
@@ -1,9 +1,14 @@
import { describe, expect, it } from "vitest";
import type { WidgetKind } from "@homarr/definitions";
import type { SettingsContextProps } from "@homarr/settings/creator";
import { createLanguageMapping } from "@homarr/translation";
import { loadAllWidgetDefinitions } from "../manifest";
import {
getWidgetOptionDescriptionTranslationNamespace,
getWidgetOptionTranslationNamespace,
} from "../option-translation";
const doesOptionRenderTranslatedCopy = (option: unknown) => {
if (typeof option !== "object" || option === null || !("type" in option)) return false;
@@ -13,6 +18,26 @@ const doesOptionRenderTranslatedCopy = (option: unknown) => {
const widgetDefinitions = await loadAllWidgetDefinitions();
const enTranslation = await createLanguageMapping().en();
const getTranslationAtPath = (path: string) => {
let value: unknown = enTranslation.default;
for (const segment of path.split(".")) {
if (typeof value !== "object" || value === null || !(segment in value)) return undefined;
value = value[segment as keyof typeof value];
}
return value;
};
const getOptionTranslation = (kind: WidgetKind, property: string) => {
return getTranslationAtPath(getWidgetOptionTranslationNamespace(kind, property));
};
const getOptionDescriptionTranslation = (kind: WidgetKind, property: string) => {
const path = getWidgetOptionDescriptionTranslationNamespace(kind, property);
return getTranslationAtPath(path ?? getWidgetOptionTranslationNamespace(kind, property));
};
describe("Widget properties with description should have matching translations", () => {
for (const [key, definition] of widgetDefinitions) {
Object.entries(definition.createOptions({} as SettingsContextProps))
@@ -20,13 +45,13 @@ describe("Widget properties with description should have matching translations",
.forEach(([optionKey, optionValue_]) => {
const optionValue = optionValue_ as { withDescription: boolean };
it(`should have matching translations for ${optionKey} option description of ${key} widget`, () => {
const option = enTranslation.default.widget[key].option;
if (!(optionKey in option)) {
const value = getOptionTranslation(key, optionKey);
const description = getOptionDescriptionTranslation(key, optionKey);
if (typeof value !== "object" || value === null || typeof description !== "object" || description === null) {
throw new Error(`Option ${optionKey} not found in translation`);
}
const value = option[optionKey as keyof typeof option];
expect("description" in value).toBe(optionValue.withDescription);
expect("description" in description).toBe(optionValue.withDescription);
});
});
}
@@ -38,11 +63,10 @@ describe("Widget properties should have matching name translations", () => {
.filter(([, option]) => doesOptionRenderTranslatedCopy(option))
.forEach(([optionKey]) => {
it(`should have matching translations for ${optionKey} option name of ${key} widget`, () => {
const option = enTranslation.default.widget[key].option;
if (!(optionKey in option)) {
const value = getOptionTranslation(key, optionKey);
if (typeof value !== "object" || value === null) {
throw new Error(`Option ${optionKey} not found in translation`);
}
const value = option[optionKey as keyof typeof option];
expect("label" in value).toBe(true);
});