162 Use hook to merge component path with translation key

This commit is contained in:
Lisa Hillebrand committed 2021-05-02 21:45:46 +02:00
1 parent f3cabe5ca1
commit 0b447178c5
2 files changed
+16 -5

No files matched your search

+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 };
}