Files
dify/web/hooks/use-knowledge.ts
Stephen Zhou 1e3823e605 chore: fix type check for i18n (#30058)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
2025-12-24 16:31:16 +08:00

33 lines
1.0 KiB
TypeScript

import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
export const useKnowledge = () => {
const { t } = useTranslation()
const formatIndexingTechnique = useCallback((indexingTechnique: string) => {
return t(`dataset.indexingTechnique.${indexingTechnique}` as any) as string
}, [t])
const formatIndexingMethod = useCallback((indexingMethod: string, isEco?: boolean) => {
if (isEco)
return t('dataset.indexingMethod.invertedIndex')
return t(`dataset.indexingMethod.${indexingMethod}` as any) as string
}, [t])
const formatIndexingTechniqueAndMethod = useCallback((indexingTechnique: string, indexingMethod: string) => {
let result = formatIndexingTechnique(indexingTechnique)
if (indexingMethod)
result += ` · ${formatIndexingMethod(indexingMethod, indexingTechnique === 'economy')}`
return result
}, [formatIndexingTechnique, formatIndexingMethod])
return {
formatIndexingTechnique,
formatIndexingMethod,
formatIndexingTechniqueAndMethod,
}
}