use-knowledge.ts 1012 B

1234567891011121314151617181920212223242526272829303132
  1. import { useCallback } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. export const useKnowledge = () => {
  4. const { t } = useTranslation()
  5. const formatIndexingTechnique = useCallback((indexingTechnique: string) => {
  6. return t(`dataset.indexingTechnique.${indexingTechnique}`)
  7. }, [t])
  8. const formatIndexingMethod = useCallback((indexingMethod: string, isEco?: boolean) => {
  9. if (isEco)
  10. return t('dataset.indexingMethod.invertedIndex')
  11. return t(`dataset.indexingMethod.${indexingMethod}`)
  12. }, [t])
  13. const formatIndexingTechniqueAndMethod = useCallback((indexingTechnique: string, indexingMethod: string) => {
  14. let result = formatIndexingTechnique(indexingTechnique)
  15. if (indexingMethod)
  16. result += ` · ${formatIndexingMethod(indexingMethod, indexingTechnique === 'economy')}`
  17. return result
  18. }, [formatIndexingTechnique, formatIndexingMethod])
  19. return {
  20. formatIndexingTechnique,
  21. formatIndexingMethod,
  22. formatIndexingTechniqueAndMethod,
  23. }
  24. }