itm-holding-package
Version:
ITM HOLDING PACKAGES
21 lines (20 loc) • 625 B
JavaScript
import { useEffect, useState } from "react";
import fr from "../dictionaries/fr.js";
import en from "../dictionaries/en.js";
import { getCookie } from "../helpers.js";
export default function useLang({ lang }) {
const [l, setLangue] = useState(lang);
const dictionaries = { fr, en };
useEffect(function () {
const language = getCookie("lang") || lang;
setLangue(language);
localStorage.setItem("lang", language);
}, []);
return {
l,
setLangue,
dico: function (key) {
return dictionaries[l][key] || dictionaries[l]['default'];
}
};
}