Files
FastGPT/packages/web/hooks/useSafeTranslation.ts
2025-07-14 19:38:31 +08:00

24 lines
513 B
TypeScript

import { useTranslation as useNextTranslation } from 'next-i18next';
import { I18N_NAMESPACES_MAP } from '../i18n/constants';
export function useTranslation() {
const { t: originalT, ...rest } = useNextTranslation();
const t = (key: string | undefined, ...args: any[]): string => {
if (!key) return '';
const ns = key.split(':')[0];
if (!I18N_NAMESPACES_MAP[ns as any]) {
return key;
}
// @ts-ignore
return originalT(key, ...args);
};
return {
t,
...rest
};
}