Browse Source

add: get cookie lang

hzwhbo 5 years ago
parent
commit
0d97dd25ee
2 changed files with 8 additions and 3 deletions
  1. 1
    0
      package.json
  2. 7
    3
      src/App.js

+ 1
- 0
package.json View File

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

+ 7
- 3
src/App.js View File

2
 import PropTypes from "prop-types";
2
 import PropTypes from "prop-types";
3
 import { message } from "antd";
3
 import { message } from "antd";
4
 import axios from "axios";
4
 import axios from "axios";
5
+import Cookies from "js-cookie";
5
 import intl from "react-intl-universal";
6
 import intl from "react-intl-universal";
6
 import { ERROR_DEFAULT, LIMIT, COMMENT_TYPE, LANGUAGE_LINK } from "./constant";
7
 import { ERROR_DEFAULT, LIMIT, COMMENT_TYPE, LANGUAGE_LINK } from "./constant";
7
 import { CommentContext } from "./Comment";
8
 import { CommentContext } from "./Comment";
65
    */
66
    */
66
   loadLocales() {
67
   loadLocales() {
67
     let { locales: currentLocale } = this.props;
68
     let { locales: currentLocale } = this.props;
69
+    const cookieLang = Cookies.get("lnk_lang");
68
     if (!currentLocale) {
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
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
77
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
74
       ? currentLocale
78
       ? currentLocale