162 Use hook to merge component path with translation key

This commit is contained in:
Lisa Hillebrand
2021-05-02 21:45:46 +02:00
parent f3cabe5ca1
commit 0b447178c5
2 changed files with 16 additions and 5 deletions
+11
View File
@@ -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 };
}