162 Use hook to merge component path with translation key
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
export default function useComponentTranslation(componentPath) {
|
||||
const { t, i18n } = useTranslation();
|
||||
function translate(code, options) {
|
||||
const mergedPath = `${componentPath}.${code}`;
|
||||
const translation = t(mergedPath, options);
|
||||
return translation !== mergedPath ? translation : t(code, options);
|
||||
}
|
||||
return { t: translate, i18n };
|
||||
}
|
||||
Reference in New Issue
Block a user