Created
March 24, 2022 12:00
-
-
Save GarryOne/79b9d8c728c70e3ac4836cbf4ff69841 to your computer and use it in GitHub Desktop.
Revisions
-
GarryOne created this gist
Mar 24, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import Cookies from 'js-cookie'; import enTrans from '@public/locales/en'; import deTrans from '@public/locales/de'; import esTrans from '@public/locales/es'; import { DEFAULT_LOCALE } from 'src/global/constants'; const useCustomTranslation = () => { const translationsByLocale = { en: enTrans, de: deTrans, es: esTrans } const locale = Cookies.get('NEXT_LOCALE') || DEFAULT_LOCALE; const t = (key: string) => { const [namespace, index] = key.split(':'); const trans = translationsByLocale[locale]; return trans[namespace] && trans[namespace][index]; } return { t }; } export default useCustomTranslation;