frigate/web/src/hooks/use-doc-domain.ts
GuoQing Liu 9b7d4d0a8f
feat: document locale url (#18409)
* feat: document locale url

* fix: remove debug code

* fix readme_cn line

* feat: add menu document locale url
2025-05-28 06:10:45 -06:00

38 lines
1.2 KiB
TypeScript

import { useTranslation } from "react-i18next";
/**
* Hook to get documentation URLs based on current language
*
* @returns {Object} An object containing:
* - getLocaleDocUrl: Function to get full documentation URL for a given path
* - docDomain: Current documentation domain based on language
*/
export function useDocDomain() {
const { i18n } = useTranslation();
// Map of language codes to their specific documentation domains
const DOC_DOMAINS: Record<string, string> = {
"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,
};
}