mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-20 20:43:01 +03:00
* Fix GenAI structured response not handling optional fields correctly * allow export thumbnails for camera-restricted roles Export thumbnails under /clips/export/ weren't classified by media auth, so roles with a camera allow-list got a 403 on every thumbnail. The thumbnail now resolves to its export's camera through a thumb_path lookup, and the camera access check applies as usual. * load i18n locales from the base url The locale load path was relative, so any URL with a trailing slash or more than one segment (like /admin/) fetched locales from under that path, got index.html back from the nginx fallback, and broke every UI string. Locales now load from the same base url as the API, which also covers HA ingress and FRIGATE_BASE_PATH. * make storage retained-segment test able to fail The old test put the retained segments after 59 older unretained ones, so cleanup freed its hourly target and stopped before it ever reached them. It passed even with the retention check removed. Retained segments now come first, and cleanup needs every unretained segment after them, so it has to skip the retained ones to finish. --------- Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
147 lines
3.5 KiB
TypeScript
147 lines
3.5 KiB
TypeScript
import i18n, { t } from "i18next";
|
|
import { initReactI18next } from "react-i18next";
|
|
import HttpBackend from "i18next-http-backend";
|
|
import { EventType } from "@/types/search";
|
|
import { baseUrl } from "@/api/baseUrl";
|
|
|
|
export const getTranslatedLabel = (
|
|
label: string,
|
|
type: EventType = "object",
|
|
) => {
|
|
if (!label) return "";
|
|
|
|
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
|
|
.use(initReactI18next)
|
|
.use(HttpBackend)
|
|
.init({
|
|
fallbackLng: "en", // use en if detected lng is not available
|
|
|
|
backend: {
|
|
loadPath: `${baseUrl}locales/{{lng}}/{{ns}}.json?v=${import.meta.env.VITE_GIT_COMMIT_HASH || "unknown"}`,
|
|
},
|
|
|
|
ns: [
|
|
"common",
|
|
"objects",
|
|
"audio",
|
|
"components/auth",
|
|
"components/camera",
|
|
"components/dialog",
|
|
"components/filter",
|
|
"components/icons",
|
|
"components/input",
|
|
"components/player",
|
|
"views/chat",
|
|
"views/classificationModel",
|
|
"views/configEditor",
|
|
"views/events",
|
|
"views/explore",
|
|
"views/exports",
|
|
"views/faceLibrary",
|
|
"views/live",
|
|
"views/motionSearch",
|
|
"views/recording",
|
|
"views/replay",
|
|
"views/search",
|
|
"views/settings",
|
|
"views/system",
|
|
"config/cameras",
|
|
"config/global",
|
|
"config/groups",
|
|
"config/validation",
|
|
],
|
|
defaultNS: "common",
|
|
|
|
react: {
|
|
transSupportBasicHtmlNodes: true,
|
|
transKeepBasicHtmlNodesFor: [
|
|
"br",
|
|
"strong",
|
|
"i",
|
|
"em",
|
|
"li",
|
|
"p",
|
|
"code",
|
|
"span",
|
|
"p",
|
|
"ul",
|
|
"li",
|
|
"ol",
|
|
],
|
|
},
|
|
interpolation: {
|
|
escapeValue: false, // react already safes from xss
|
|
},
|
|
keySeparator: ".",
|
|
parseMissingKeyHandler: (key: string) => {
|
|
const parts = key.split(".");
|
|
|
|
if (parts[0] === "time" && parts[1]?.includes("formattedTimestamp")) {
|
|
// Extract the format type from the last part (12hour, 24hour)
|
|
const formatType = parts[parts.length - 1];
|
|
|
|
// Return actual date-fns format strings as fallbacks
|
|
const formatDefaults: Record<string, string> = {
|
|
"12hour": "h:mm aaa",
|
|
"24hour": "HH:mm",
|
|
};
|
|
|
|
if (formatDefaults[formatType]) {
|
|
return formatDefaults[formatType];
|
|
}
|
|
}
|
|
|
|
// Handle special cases for objects and audio
|
|
if (parts[0] === "object" || parts[0] === "audio") {
|
|
return (
|
|
parts[1]
|
|
?.split("_")
|
|
.map(
|
|
(word) =>
|
|
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
|
)
|
|
.join(" ") || key
|
|
);
|
|
}
|
|
|
|
// For nested keys, try to make them more readable
|
|
if (parts.length > 1) {
|
|
const lastPart = parts[parts.length - 1];
|
|
return lastPart
|
|
.split("_")
|
|
.map(
|
|
(word) =>
|
|
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
|
)
|
|
.join(" ");
|
|
}
|
|
|
|
// For single keys, just smart-capitalize and format
|
|
return key
|
|
.split("_")
|
|
.map(
|
|
(word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
|
)
|
|
.join(" ");
|
|
},
|
|
});
|
|
|
|
export default i18n;
|