From 9b7d4d0a8fc57dad1d74a12af7e96758d9da191a Mon Sep 17 00:00:00 2001 From: GuoQing Liu <842607283@qq.com> Date: Wed, 28 May 2025 20:10:45 +0800 Subject: [PATCH] feat: document locale url (#18409) * feat: document locale url * fix: remove debug code * fix readme_cn line * feat: add menu document locale url --- README_CN.md | 1 + web/src/components/menu/GeneralSettings.tsx | 5 ++- web/src/components/overlay/LogInfoDialog.tsx | 19 ++++++---- .../overlay/detail/AnnotationSettingsPane.tsx | 4 +- .../overlay/detail/FaceCreateWizardDialog.tsx | 5 ++- .../settings/CameraStreamingDialog.tsx | 7 +++- .../settings/MotionMaskEditPane.tsx | 4 +- web/src/components/settings/ZoneEditPane.tsx | 6 ++- web/src/hooks/use-doc-domain.ts | 37 +++++++++++++++++++ web/src/pages/Explore.tsx | 4 +- web/src/views/live/LiveCameraView.tsx | 18 ++++++--- web/src/views/settings/CameraSettingsView.tsx | 4 +- .../settings/EnrichmentsSettingsView.tsx | 14 +++++-- .../settings/FrigatePlusSettingsView.tsx | 4 +- web/src/views/settings/MasksAndZonesView.tsx | 13 +++++-- web/src/views/settings/MotionTunerView.tsx | 4 +- .../settings/NotificationsSettingsView.tsx | 8 ++-- web/src/views/settings/ObjectSettingsView.tsx | 7 +++- 18 files changed, 128 insertions(+), 36 deletions(-) create mode 100644 web/src/hooks/use-doc-domain.ts diff --git a/README_CN.md b/README_CN.md index efcea3480..cacbd3d2b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -61,4 +61,5 @@ ## 非官方中文讨论社区 欢迎加入中文讨论QQ群:1043861059 + Bilibili:https://space.bilibili.com/3546894915602564 diff --git a/web/src/components/menu/GeneralSettings.tsx b/web/src/components/menu/GeneralSettings.tsx index af5855815..35231c5aa 100644 --- a/web/src/components/menu/GeneralSettings.tsx +++ b/web/src/components/menu/GeneralSettings.tsx @@ -64,12 +64,15 @@ import { FrigateConfig } from "@/types/frigateConfig"; import { useTranslation } from "react-i18next"; import { supportedLanguageKeys } from "@/lib/const"; +import { useDocDomain } from "@/hooks/use-doc-domain"; + type GeneralSettingsProps = { className?: string; }; export default function GeneralSettings({ className }: GeneralSettingsProps) { const { t } = useTranslation(["common", "views/settings"]); + const { getLocaleDocUrl } = useDocDomain(); const { data: profile } = useSWR("profile"); const { data: config } = useSWR("config"); const logoutUrl = config?.proxy?.logout_url || "/api/logout"; @@ -479,7 +482,7 @@ export default function GeneralSettings({ className }: GeneralSettingsProps) { {t("menu.help")} - + { if (!content) { return []; } const links = []; - if (/Could not clear [\d.]* currently [\d.]*/.exec(content)) { links.push({ - link: "https://docs.frigate.video/configuration/record#will-frigate-delete-old-recordings-if-my-storage-runs-out", + link: getLocaleDocUrl( + "configuration/record#will-frigate-delete-old-recordings-if-my-storage-runs-out", + ), text: "Frigate Automatic Storage Cleanup", }); } if (/Did not detect hwaccel/.exec(content)) { links.push({ - link: "https://docs.frigate.video/configuration/hardware_acceleration", + link: getLocaleDocUrl("configuration/hardware_acceleration"), text: "Setup Hardware Acceleration", }); } @@ -139,25 +142,27 @@ function useHelpfulLinks(content: string | undefined) { content.includes("No VA display found for device /dev/dri/renderD128") ) { links.push({ - link: "https://docs.frigate.video/configuration/hardware_acceleration", + link: getLocaleDocUrl("configuration/hardware_acceleration"), text: "Verify Hardware Acceleration Setup", }); } if (content.includes("No EdgeTPU was detected")) { links.push({ - link: "https://docs.frigate.video/troubleshooting/edgetpu", + link: getLocaleDocUrl("troubleshooting/edgetpu"), text: "Troubleshoot Coral", }); } if (content.includes("The current SHM size of")) { links.push({ - link: "https://docs.frigate.video/frigate/installation/#calculating-required-shm-size", + link: getLocaleDocUrl( + "frigate/installation/#calculating-required-shm-size", + ), text: "Calculate Correct SHM Size", }); } return links; - }, [content]); + }, [content, getLocaleDocUrl]); } diff --git a/web/src/components/overlay/detail/AnnotationSettingsPane.tsx b/web/src/components/overlay/detail/AnnotationSettingsPane.tsx index 682c0379d..f71c2d6ba 100644 --- a/web/src/components/overlay/detail/AnnotationSettingsPane.tsx +++ b/web/src/components/overlay/detail/AnnotationSettingsPane.tsx @@ -27,6 +27,7 @@ import ActivityIndicator from "@/components/indicators/activity-indicator"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; import { Trans, useTranslation } from "react-i18next"; +import { useDocDomain } from "@/hooks/use-doc-domain"; type AnnotationSettingsPaneProps = { event: Event; @@ -43,6 +44,7 @@ export function AnnotationSettingsPane({ setAnnotationOffset, }: AnnotationSettingsPaneProps) { const { t } = useTranslation(["views/explore"]); + const { getLocaleDocUrl } = useDocDomain(); const { data: config, mutate: updateConfig } = useSWR("config"); @@ -180,7 +182,7 @@ export function AnnotationSettingsPane({
("config"); const [isLoading, setIsLoading] = useState(false); @@ -220,7 +223,7 @@ export function CameraStreamingDialog({ })}
("config"); @@ -249,7 +251,7 @@ export default function MotionMaskEditPane({
("config"); @@ -673,7 +675,9 @@ export default function ZoneEditPane({ {t("masksAndZones.zones.speedEstimation.desc")}
= { + "zh-CN": "docs.frigate-cn.video", + // Add other language-specific domains here as needed + }; + + // Get the appropriate documentation domain for current language + const docDomain = DOC_DOMAINS[i18n.language] || "docs.frigate.video"; + + /** + * Get full documentation URL for a given path + * @param {string} path - Documentation path (e.g. "/configuration/live") + * @returns {string} Full documentation URL + */ + const getLocaleDocUrl = (path: string): string => { + // Ensure path starts with a slash + const normalizedPath = path.startsWith("/") ? path : `/${path}`; + return `https://${docDomain}${normalizedPath}`; + }; + + return { + getLocaleDocUrl, + docDomain, + }; +} diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx index 7e412201e..62d55fee9 100644 --- a/web/src/pages/Explore.tsx +++ b/web/src/pages/Explore.tsx @@ -22,6 +22,7 @@ import { Link } from "react-router-dom"; import { toast } from "sonner"; import useSWR from "swr"; import useSWRInfinite from "swr/infinite"; +import { useDocDomain } from "@/hooks/use-doc-domain"; const API_LIMIT = 25; @@ -29,6 +30,7 @@ export default function Explore() { // search field handler const { t } = useTranslation(["views/explore"]); + const { getLocaleDocUrl } = useDocDomain(); const { data: config } = useSWR("config", { revalidateOnFocus: false, @@ -468,7 +470,7 @@ export default function Explore() {
("config"); @@ -352,7 +354,7 @@ export default function CameraSettingsView({

("config"); const [changedValue, setChangedValue] = useState(false); @@ -256,7 +258,7 @@ export default function EnrichmentsSettingsView({
("config"); const [changedValue, setChangedValue] = useState(false); @@ -451,7 +453,7 @@ export default function FrigatePlusSettingsView({

("config"); const [allPolygons, setAllPolygons] = useState([]); const [editingPolygons, setEditingPolygons] = useState([]); @@ -513,7 +516,7 @@ export default function MasksAndZonesView({

{t("masksAndZones.zones.desc.title")}

{t("masksAndZones.motionMasks.desc.title")}

{t("masksAndZones.objectMasks.desc.title")}

("config"); const [changedValue, setChangedValue] = useState(false); @@ -198,7 +200,7 @@ export default function MotionTunerView({
( "config", @@ -316,7 +318,7 @@ export default function NotificationView({

{t("notification.notificationSettings.desc")}

{t("notification.notificationSettings.desc")}

("config"); const containerRef = useRef(null); @@ -258,7 +261,9 @@ export default function ObjectSettingsView({ {t("debug.objectShapeFilterDrawing.tips")}