Browse Source

feat: 将SUPPORT_LOCALES LOCALES_RESPONSE 放在单独的文件中

node 5 years ago
parent
commit
e469428e0c
3 changed files with 41 additions and 61 deletions
  1. 1
    45
      src/App.js
  2. 0
    1
      src/components/ContentItem/index.js
  3. 40
    15
      src/lang/index.js

+ 1
- 45
src/App.js View File

@@ -10,58 +10,16 @@ import CommentInput from "./components/CommentInput";
10 10
 import CommentList from "./components/CommentList";
11 11
 import Editor from "./components/Editor";
12 12
 import RenderText from "./components/RenderText";
13
-// import lang from "./lang";
13
+import { SUPPORT_LOCALES, LOCALES_RESPONSE } from "./lang";
14 14
 import USdata from "./lang/en-US.js";
15 15
 import CNdata from "./lang/zh-CN.js";
16 16
 import "./App.css";
17
-// import styles from "./App.module.css";
18
-
19
-/**
20
- * 当前支持的语言
21
- */
22
-const SUPPORT_LOCALES = [
23
-  {
24
-    name: "English",
25
-    value: "en-US"
26
-  },
27
-  {
28
-    name: "简体中文",
29
-    value: "zh-CN"
30
-  }
31
-];
32 17
 
33 18
 const LOCALES = {
34 19
   "zh-CN": CNdata,
35 20
   "en-US": USdata
36 21
 };
37 22
 
38
-const LOCALES_RESPONSE = {
39
-  "zh-CN": {
40
-    "not found": "没有数据",
41
-    "auth failed": "请先登录",
42
-    "create comment failed": "创建评论失败",
43
-    "comment favor failed": "评论点赞失败",
44
-    "delete comment favor failed": "评论取消点赞失败",
45
-    "get comments failed": "获取评论列表失败",
46
-    "create reply failed": "创建回复失败",
47
-    "reply favor failed": "回复点赞失败",
48
-    "delete reply favor failed": "删除回复点赞失败",
49
-    "get replies failed": "获取回复列表失败"
50
-  },
51
-  "en-US": {
52
-    "not found": "no data",
53
-    "auth failed": "please log in first",
54
-    "create comment failed": "Failed to create comment",
55
-    "comment favor failed": "Comment likes failure",
56
-    "delete comment favor failed": "评论取消点赞失败",
57
-    "get comments failed": "Comment cancels praise failure",
58
-    "create reply failed": "Create reply failed",
59
-    "reply favor failed": "Reply to praise failed",
60
-    "delete reply favor failed": "Delete reply clicks failed",
61
-    "get replies failed": "Failed to get reply list"
62
-  }
63
-};
64
-
65 23
 class App extends Component {
66 24
   constructor(props) {
67 25
     super(props);
@@ -119,11 +77,9 @@ class App extends Component {
119 77
         urlLocaleKey: "lang"
120 78
       });
121 79
     }
122
-    console.log("currentLocale", currentLocale);
123 80
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
124 81
       ? currentLocale
125 82
       : "zh-CN";
126
-    console.log("locales is", LOCALES[currentLocale]);
127 83
     intl
128 84
       .init({
129 85
         currentLocale,

+ 0
- 1
src/components/ContentItem/index.js View File

@@ -85,7 +85,6 @@ class CommentItem extends Component {
85 85
     } = this.props;
86 86
 
87 87
     const { locale } = this.props.app;
88
-    console.log("locale is", locale);
89 88
     const { showInput } = this.state;
90 89
 
91 90
     let newContent = content.content;

+ 40
- 15
src/lang/index.js View File

@@ -1,16 +1,41 @@
1
-// 语言包
2
-// 英文短语和中文提示的对应
3
-const data = {
4
-  "not found": "没有数据",
5
-  "auth failed": "请先登录",
6
-  "create comment failed": "创建评论失败",
7
-  "comment favor failed": "评论点赞失败",
8
-  "delete comment favor failed": "评论取消点赞失败",
9
-  "get comments failed": "获取评论列表失败",
10
-  "create reply failed": "创建回复失败",
11
-  "reply favor failed": "回复点赞失败",
12
-  "delete reply favor failed": "删除回复点赞失败",
13
-  "get replies failed": "获取回复列表失败"
14
-};
1
+/**
2
+ * 当前支持的语言
3
+ */
4
+export const SUPPORT_LOCALES = [
5
+  {
6
+    name: "English",
7
+    value: "en-US"
8
+  },
9
+  {
10
+    name: "简体中文",
11
+    value: "zh-CN"
12
+  }
13
+];
15 14
 
16
-export default data;
15
+// 服务端返回的英文短语和中文提示的对应
16
+export const LOCALES_RESPONSE = {
17
+  "zh-CN": {
18
+    "not found": "没有数据",
19
+    "auth failed": "请先登录",
20
+    "create comment failed": "创建评论失败",
21
+    "comment favor failed": "评论点赞失败",
22
+    "delete comment favor failed": "评论取消点赞失败",
23
+    "get comments failed": "获取评论列表失败",
24
+    "create reply failed": "创建回复失败",
25
+    "reply favor failed": "回复点赞失败",
26
+    "delete reply favor failed": "删除回复点赞失败",
27
+    "get replies failed": "获取回复列表失败"
28
+  },
29
+  "en-US": {
30
+    "not found": "no data",
31
+    "auth failed": "please log in first",
32
+    "create comment failed": "Failed to create comment",
33
+    "comment favor failed": "Comment likes failure",
34
+    "delete comment favor failed": "评论取消点赞失败",
35
+    "get comments failed": "Comment cancels praise failure",
36
+    "create reply failed": "Create reply failed",
37
+    "reply favor failed": "Reply to praise failed",
38
+    "delete reply favor failed": "Delete reply clicks failed",
39
+    "get replies failed": "Failed to get reply list"
40
+  }
41
+};