mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-12 18:17:36 +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) => {
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user