mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-14 19:12:08 +03:00
ensure i18n audio label keys are translated
don't assume they are in the objects namespace
This commit is contained in:
parent
e592c7044b
commit
e9dc622cc3
@ -5,7 +5,21 @@ import HttpBackend from "i18next-http-backend";
|
|||||||
export const getTranslatedLabel = (label: string) => {
|
export const getTranslatedLabel = (label: string) => {
|
||||||
if (!label) return "";
|
if (!label) return "";
|
||||||
|
|
||||||
return t(`${label.replace(/\s+/g, "_").toLowerCase()}`, { ns: "objects" });
|
const normalize = (s: string) =>
|
||||||
|
s
|
||||||
|
.trim()
|
||||||
|
.replace(/[-'\s]+/g, "_")
|
||||||
|
.replace(/__+/g, "_")
|
||||||
|
.replace(/^_+|_+$/g, "")
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
const key = normalize(label);
|
||||||
|
|
||||||
|
if (i18n.exists(key, { ns: "objects" })) return t(key, { ns: "objects" });
|
||||||
|
if (i18n.exists(key, { ns: "audio" })) return t(key, { ns: "audio" });
|
||||||
|
|
||||||
|
// fallback
|
||||||
|
return t(key, { ns: "objects" });
|
||||||
};
|
};
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user