Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| front:traductions [2025/09/29 16:44] – [Utiliser les traductions] paolo | front:traductions [2025/09/29 17:10] (Version actuelle) – [Configurer i18next] paolo | ||
|---|---|---|---|
| Ligne 65: | Ligne 65: | ||
| ### Configurer i18next | ### Configurer i18next | ||
| - | Pour configurer i18n, nous avons besoin d' | + | Pour cela, nous devons: |
| + | |||
| + | * Créer un fichier de configuration dans lequel | ||
| ``` | ``` | ||
| Ligne 89: | Ligne 91: | ||
| ``` | ``` | ||
| - | Comme nous avons " | + | * Passer cette configuration au '' |
| + | |||
| + | ``` | ||
| + | // src/ | ||
| + | |||
| + | import { I18nextProvider as Provider } from "react-i18next"; | ||
| + | import { useEffect } from " | ||
| + | import { i18n } from " | ||
| + | import { useSelector } from " | ||
| + | |||
| + | export const I18nextProvider = (props) => { | ||
| + | const { children } = props; | ||
| + | |||
| + | const settings = useSelector(state => state.settings.data) ?? {}; | ||
| + | const { lng } = settings; | ||
| + | |||
| + | useEffect(() => { | ||
| + | i18n.changeLanguage(lng); | ||
| + | }, [lng]); | ||
| + | |||
| + | return ( | ||
| + | < | ||
| + | {children} | ||
| + | </ | ||
| + | ); | ||
| + | }; | ||
| + | ``` | ||
| + | |||
| + | Comme nous sommes au sein du '' | ||
| + | |||
| + | ``` | ||
| + | // src/ | ||
| + | |||
| + | import { Router } from " | ||
| + | import { ReduxProvider } from " | ||
| + | import { I18nextProvider } from " | ||
| + | |||
| + | export const App = () => { | ||
| + | return ( | ||
| + | < | ||
| + | < | ||
| + | <Router /> | ||
| + | </ | ||
| + | </ | ||
| + | ); | ||
| + | }; | ||
| + | ``` | ||
| + | |||
| + | Désormais les traductions sont accessibles dans n' | ||
| + | . | ||
| ### Utiliser les traductions | ### Utiliser les traductions | ||
| Ligne 113: | Ligne 164: | ||
| | | ||
| return ( | return ( | ||
| - | // page login | + | <div className=" |
| + | <form | ||
| + | onSubmit={handleFormOnSubmit} | ||
| + | className=" | ||
| + | > | ||
| + | <Input | ||
| + | id=" | ||
| + | name=" | ||
| + | label={t(" | ||
| + | type=" | ||
| + | placeholder={t(" | ||
| + | | ||
| + | <Input | ||
| + | id=" | ||
| + | name=" | ||
| + | label={t(" | ||
| + | type=" | ||
| + | placeholder={t(" | ||
| + | /> | ||
| + | <button className=" | ||
| + | {t(" | ||
| + | </ | ||
| + | </ | ||
| + | </div> | ||
| ); | ); | ||
| }; | }; | ||
| ``` | ``` | ||
| + | |||
| + | Pour ne pas à réécrire à chaque fois '' | ||