diff --git a/src/context/UserContext.js b/src/context/UserContext.js index c4dc314..262904f 100644 --- a/src/context/UserContext.js +++ b/src/context/UserContext.js @@ -1,10 +1,11 @@ import { createContext, useEffect, useState } from "react"; +import CountriesJSON from "../data/countries/countries.json"; export const UserContext = createContext(); export function UserContextProvider({ children }) { const [language, setLanguage] = useState("FR"); - const [country, setCountry] = useState({ name: "belgique", iso: "BE" }); + const [country, setCountry] = useState({ name: "belgique", iso: "BE", label: "Belgique" }); const [profile, setProfile] = useState("lhoist_employee"); const [screensTranslations, setScreensTranslations] = useState({}); @@ -21,6 +22,12 @@ export function UserContextProvider({ children }) { // Appeler la fonction loadTranslations avec la langue actuelle loadTranslations(language); + + // ADAPTING COUNTRY LABEL TO LANGUAGE + const currentCountry = CountriesJSON.find( + (countryJson) => countryJson.alpha2 === country.iso.toLowerCase() + ); + setCountry({ ...country, label: currentCountry[language.toLowerCase()] }); }, [language]); function changeLanguage() { @@ -45,6 +52,7 @@ export function UserContextProvider({ children }) { screensTranslations, changeLanguage, country, + setLanguage, changeCountry, profile, changeProfile,