Pārlūkot izejas kodu

add: get cookie lang

hzwhbo 5 gadus atpakaļ
vecāks
revīzija
0d97dd25ee
2 mainītis faili ar 8 papildinājumiem un 3 dzēšanām
  1. 1
    0
      package.json
  2. 7
    3
      src/App.js

+ 1
- 0
package.json Parādīt failu

@@ -17,6 +17,7 @@
17 17
     "antd": "^3.6.6",
18 18
     "axios": "^0.18.0",
19 19
     "dayjs": "^1.7.2",
20
+    "js-cookie": "^2.2.0",
20 21
     "prop-types": "^15.6.2",
21 22
     "react": "^16.4.1",
22 23
     "react-dom": "^16.4.1",

+ 7
- 3
src/App.js Parādīt failu

@@ -2,6 +2,7 @@ import React, { Component } from "react";
2 2
 import PropTypes from "prop-types";
3 3
 import { message } from "antd";
4 4
 import axios from "axios";
5
+import Cookies from "js-cookie";
5 6
 import intl from "react-intl-universal";
6 7
 import { ERROR_DEFAULT, LIMIT, COMMENT_TYPE, LANGUAGE_LINK } from "./constant";
7 8
 import { CommentContext } from "./Comment";
@@ -65,10 +66,13 @@ class App extends Component {
65 66
    */
66 67
   loadLocales() {
67 68
     let { locales: currentLocale } = this.props;
69
+    const cookieLang = Cookies.get("lnk_lang");
68 70
     if (!currentLocale) {
69
-      currentLocale = intl.determineLocale({
70
-        urlLocaleKey: "lang"
71
-      });
71
+      currentLocale =
72
+        cookieLang ||
73
+        intl.determineLocale({
74
+          urlLocaleKey: "lang"
75
+        });
72 76
     }
73 77
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
74 78
       ? currentLocale