mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-07 02:18:07 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user