|
@ -1,5 +1,6 @@ |
|
|
import { useCallback } from 'react'; |
|
|
import { useCallback } from 'react'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
|
|
|
import { TOptions } from 'i18next'; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* A hook which returns a `t` function that inserts a prefix in each key lookup |
|
|
* A hook which returns a `t` function that inserts a prefix in each key lookup |
|
@ -9,7 +10,7 @@ const usePrefixedTranslation = (prefix: string) => { |
|
|
const { t } = useTranslation(); |
|
|
const { t } = useTranslation(); |
|
|
// the new `t` function that will append the prefix
|
|
|
// the new `t` function that will append the prefix
|
|
|
const translate = useCallback( |
|
|
const translate = useCallback( |
|
|
(key: string, options?: string | object) => { |
|
|
(key: string, options?: string | TOptions<any> | undefined) => { |
|
|
// if the key contains a '.', then don't add the prefix
|
|
|
// if the key contains a '.', then don't add the prefix
|
|
|
return key.includes('.') ? t(key, options) : t(`${prefix}.${key}`, options); |
|
|
return key.includes('.') ? t(key, options) : t(`${prefix}.${key}`, options); |
|
|
}, |
|
|
}, |
|
|