1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/components/hooks/useTranslation.tsx
2021-05-05 15:58:21 -07:00

16 lines
607 B
TypeScript

import { useMainContext } from 'components/context/MainContext'
import get from 'lodash/get'
// The idea of this component is to mimic a popular i18n library (i18next)
// so that we can set ourselves up to transition to it (or a similar library) in the future
export const useTranslation = (translationGroup: string) => {
const { data } = useMainContext()
return {
t: (strings: TemplateStringsArray | string, ...values: Array<any>) => {
const key = typeof strings === 'string' ? strings : String.raw(strings, ...values)
return get((data.ui as any)[translationGroup], key)
},
}
}