Fix I18n audio labels (#20508)

* ensure i18n audio label keys are translated

don't assume they are in the objects namespace

* add missing audio labels

* Improve handling of label types

* simplify

* fixes

---------

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
This commit is contained in:
Josh Hawkins
2025-10-15 14:02:08 -05:00
committed by GitHub
parent e592c7044b
commit 75d7049b6d
6 changed files with 123 additions and 14 deletions

View File

@@ -1,11 +1,29 @@
import i18n, { t } from "i18next";
import { initReactI18next } from "react-i18next";
import HttpBackend from "i18next-http-backend";
import { EventType } from "@/types/search";
export const getTranslatedLabel = (label: string) => {
export const getTranslatedLabel = (
label: string,
type: EventType = "object",
) => {
if (!label) return "";
return t(`${label.replace(/\s+/g, "_").toLowerCase()}`, { ns: "objects" });
if (type === "manual") return label;
const normalize = (s: string) =>
s
.trim()
.replace(/[-'\s]+/g, "_")
.replace(/__+/g, "_")
.replace(/^_+|_+$/g, "")
.toLowerCase();
const key = normalize(label);
const ns = type === "audio" ? "audio" : "objects";
return t(key, { ns });
};
i18n