Browse Source

setup de react-intl

Lou 3 years ago
parent
commit
b1f24e12c8
6 changed files with 34 additions and 5 deletions
  1. 0
    0
      src/lang/en.json
  2. 0
    0
      src/lang/fr_FR.json
  3. 9
    3
      src/main.jsx
  4. 17
    2
      src/pages/Home/index.jsx
  5. 4
    0
      src/translations/en.json
  6. 4
    0
      src/translations/fr_FR.json

+ 0
- 0
src/lang/en.json View File


+ 0
- 0
src/lang/fr_FR.json View File


+ 9
- 3
src/main.jsx View File

@@ -7,19 +7,25 @@ import { store, persistor } from "./redux/store/index";
7 7
 
8 8
 import App from "./App.jsx";
9 9
 import "./main.scss";
10
-import fr_FR from "./lang/fr_FR.json";
11
-import en_default from "./lang/en.json";
10
+
11
+import fr_FR from "./translations/fr_FR.json";
12
+import en_default from "./translations/en.json";
12 13
 
13 14
 const locale = navigator.language;
14 15
 let lang = "";
15 16
 if (locale !== "fr") {
17
+	lang = en_default;
18
+} else {
19
+	lang = fr_FR;
16 20
 }
17 21
 
18 22
 ReactDOM.render(
19 23
 	<React.StrictMode>
20 24
 		<Provider store={store}>
21 25
 			<PersistGate loading={null} persistor={persistor}>
22
-				<App />
26
+				<IntlProvider locale={locale} messages={lang}>
27
+					<App />
28
+				</IntlProvider>
23 29
 			</PersistGate>
24 30
 		</Provider>
25 31
 	</React.StrictMode>,

+ 17
- 2
src/pages/Home/index.jsx View File

@@ -1,6 +1,7 @@
1 1
 import React, { useEffect } from "react";
2 2
 import { useLocation } from "react-router";
3 3
 import { useSelector } from "react-redux";
4
+import { FormattedMessage } from "react-intl";
4 5
 
5 6
 import Cookies from "js-cookie";
6 7
 
@@ -14,13 +15,27 @@ const Home = () => {
14 15
 			<h2>Home</h2>
15 16
 			{currentUser && (
16 17
 				<div>
17
-					<p>Utilisateurice connecté·e, bravo !</p>
18
+					<p>
19
+						<FormattedMessage
20
+							id="home.connected"
21
+							defaultMessage="Utilisateurice connecté·e - {what}"
22
+							description="verification header - connected"
23
+							values={{ what: "react-intl" }}
24
+						/>
25
+					</p>
18 26
 				</div>
19 27
 			)}
20 28
 
21 29
 			{!currentUser && (
22 30
 				<div>
23
-					<p>Utilisateurice non connecté·e.</p>
31
+					<p>
32
+						<FormattedMessage
33
+							id="home.notConnected"
34
+							defaultMessage="Utilisateurice non connecté·e - {what}"
35
+							description="verification header - not connected"
36
+							values={{ what: "react-intl" }}
37
+						/>
38
+					</p>
24 39
 				</div>
25 40
 			)}
26 41
 			<p>{location.state && location.state.status}</p>

+ 4
- 0
src/translations/en.json View File

@@ -0,0 +1,4 @@
1
+{
2
+	"home.connected": "User is connected",
3
+	"home.notConnected": "User is not connected"
4
+}

+ 4
- 0
src/translations/fr_FR.json View File

@@ -0,0 +1,4 @@
1
+{
2
+	"home.connected": "Utilisateurice connecté·e - lol",
3
+	"home.notConnected": "Utilisateurice non connecté·e - lol"
4
+}

Loading…
Cancel
Save