浏览代码

update: 修改中英文文案及页面代码

node 6 年前
父节点
当前提交
fb5bdd77a4

+ 14
- 10
src/App.js 查看文件

@@ -11,6 +11,8 @@ import CommentList from "./components/CommentList";
11 11
 import Editor from "./components/Editor";
12 12
 import RenderText from "./components/RenderText";
13 13
 import lang from "./lang";
14
+import USdata from "./lang/en-US.js";
15
+import CNdata from "./lang/zh-CN.js";
14 16
 import "./App.css";
15 17
 // import styles from "./App.module.css";
16 18
 
@@ -28,6 +30,11 @@ const SUPPORT_LOCALES = [
28 30
   }
29 31
 ];
30 32
 
33
+const LOCALES = {
34
+  "zh-CN": CNdata,
35
+  "en-US": USdata
36
+};
37
+
31 38
 class App extends Component {
32 39
   constructor(props) {
33 40
     super(props);
@@ -88,16 +95,13 @@ class App extends Component {
88 95
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
89 96
       ? currentLocale
90 97
       : "zh-CN";
91
-    this.axios
92
-      .get(`locales/${currentLocale}.json`)
93
-      .then(res => {
94
-        console.log("App locale data", res.data);
95
-        return intl.init({
96
-          currentLocale,
97
-          locales: {
98
-            [currentLocale]: res.data
99
-          }
100
-        });
98
+    console.log("locales is", LOCALES[currentLocale]);
99
+    intl
100
+      .init({
101
+        currentLocale,
102
+        locales: {
103
+          [currentLocale]: LOCALES[currentLocale]
104
+        }
101 105
       })
102 106
       .then(() => {
103 107
         this.setState({ initDone: true });

+ 10
- 10
src/components/CommentBox/index.js 查看文件

@@ -1,6 +1,7 @@
1 1
 import React, { Component } from "react";
2 2
 import PropTypes from "prop-types";
3 3
 import { Icon } from "antd";
4
+import intl from "react-intl-universal";
4 5
 import Comment from "../../Comment";
5 6
 import ContentItem from "./../ContentItem";
6 7
 import "./index.css";
@@ -60,21 +61,20 @@ class CommentBox extends Component {
60 61
                   action="replyToReply" // 回复的回复
61 62
                 />,
62 63
                 <div className="comment-more-box" key="show_more_button">
63
-                  {!isNoMoreReply &&
64
-                    replyCount !== len && (
65
-                      <span
66
-                        className="comment-show-more"
67
-                        onClick={() => this.handleGetMoreReply(commentId)}
68
-                      >
69
-                        查看更多回复
70
-                      </span>
71
-                    )}
64
+                  {!isNoMoreReply && replyCount !== len && (
65
+                    <span
66
+                      className="comment-show-more"
67
+                      onClick={() => this.handleGetMoreReply(commentId)}
68
+                    >
69
+                      {intl.get("reply.moreReply")}
70
+                    </span>
71
+                  )}
72 72
 
73 73
                   <a
74 74
                     style={{ float: "right" }}
75 75
                     onClick={this.handleToggleReply}
76 76
                   >
77
-                    <Icon type="up" /> 收起回复
77
+                    <Icon type="up" /> {intl.get("reply.collapse")}
78 78
                   </a>
79 79
                 </div>
80 80
               ];

+ 4
- 2
src/components/CommentList/index.js 查看文件

@@ -1,5 +1,6 @@
1 1
 import React, { Component } from "react";
2 2
 import { Spin, Pagination } from "antd";
3
+import intl from "react-intl-universal";
3 4
 import Comment from "../../Comment";
4 5
 import CommentBox from "../CommentBox";
5 6
 import "./index.css";
@@ -35,7 +36,7 @@ class CommentList extends Component {
35 36
               onPageChange(page + 1);
36 37
             }}
37 38
           >
38
-            <span>查看更多评论</span>
39
+            <span>{intl.get("comment.moreComment")}</span>
39 40
           </div>
40 41
         );
41 42
       } else {
@@ -67,7 +68,8 @@ class CommentList extends Component {
67 68
     return (
68 69
       <div>
69 70
         <Spin spinning={spinning}>
70
-          <div>共 {total} 条评论</div>
71
+          {/* <div>共 {total} 条评论</div> */}
72
+          <div>{intl.get("comment.totalComment", { total })}</div>
71 73
           {list.map(item => (
72 74
             <CommentBox content={item} key={item.id} commentId={item.id} />
73 75
           ))}

+ 58
- 52
src/components/ContentItem/index.js 查看文件

@@ -3,7 +3,9 @@ import PropTypes from "prop-types";
3 3
 import { Avatar, Icon, Tooltip, Popconfirm } from "antd";
4 4
 import dayjs from "dayjs";
5 5
 import "dayjs/locale/zh-cn";
6
+// import 'dayjs/locale/es';
6 7
 import relativeTime from "dayjs/plugin/relativeTime";
8
+import intl from "react-intl-universal";
7 9
 import Comment from "../../Comment";
8 10
 import CommentInput from "../CommentInput";
9 11
 import avatar from "../../avatar";
@@ -12,7 +14,7 @@ import { IMAGE_SPLIT } from "../../constant";
12 14
 import "./index.css";
13 15
 import ImagePreviewer from "../ImagePreviewer/ImagePreviewer";
14 16
 
15
-dayjs.locale("zh-cn");
17
+// dayjs.locale("zh-cn");
16 18
 dayjs.extend(relativeTime);
17 19
 
18 20
 class CommentItem extends Component {
@@ -115,7 +117,7 @@ class CommentItem extends Component {
115 117
             {/* <a href={`/${content.user_id}`}>
116 118
               {content.user_name || "暂无昵称"}
117 119
             </a> */}
118
-            <strong>{content.user_name || "游客"}</strong>
120
+            <strong>{content.user_name || intl.get("comment.tourist")}</strong>
119 121
             <span style={{ marginLeft: 10 }}>
120 122
               <Tooltip
121 123
                 placement="top"
@@ -124,6 +126,7 @@ class CommentItem extends Component {
124 126
                 )}
125 127
               >
126 128
                 {dayjs(content.created * 1000).fromNow()}
129
+                {/* {dayjs(content.created * 1000).locale('zh-cn').fromNow()} */}
127 130
               </Tooltip>
128 131
             </span>
129 132
           </div>
@@ -136,66 +139,67 @@ class CommentItem extends Component {
136 139
             }}
137 140
           />
138 141
           {// image为空时不渲染comment-item-image
139
-          imageList.length > 0 &&
140
-            imageList[0] !== "" && (
141
-              <div className="comment-item-image">
142
-                {!this.state.showPreviewer &&
143
-                  imgs.map((item, index) => {
144
-                    if (item.type === "divider") {
145
-                      return (
146
-                        <div className="comment-item-image-wrapper" key={index}>
147
-                          <div className="comment-img-divider" />
148
-                          {/* <img src={item} alt={item} className="comment-img" /> */}
149
-                        </div>
150
-                      );
151
-                    }
142
+          imageList.length > 0 && imageList[0] !== "" && (
143
+            <div className="comment-item-image">
144
+              {!this.state.showPreviewer &&
145
+                imgs.map((item, index) => {
146
+                  if (item.type === "divider") {
152 147
                     return (
153
-                      <div
154
-                        className="comment-item-image-wrapper"
155
-                        key={index}
156
-                        onClick={() => {
157
-                          let i = index;
158
-                          if (needClear) {
159
-                            if (index > 3) {
160
-                              i -= 1;
161
-                            }
162
-                            if (index > 7) {
163
-                              i -= 1;
164
-                            }
165
-                          }
166
-                          this.showPreviewer(i);
167
-                        }}
168
-                      >
169
-                        <div
170
-                          style={{ backgroundImage: `url(${item})` }}
171
-                          className="comment-img-thumbnail"
172
-                        />
148
+                      <div className="comment-item-image-wrapper" key={index}>
149
+                        <div className="comment-img-divider" />
173 150
                         {/* <img src={item} alt={item} className="comment-img" /> */}
174 151
                       </div>
175 152
                     );
176
-                  })}
177
-                {this.state.showPreviewer && (
178
-                  <ImagePreviewer
179
-                    list={imageList}
180
-                    index={this.state.previewerIndex}
181
-                    onFold={this.hidePreviewer}
182
-                  />
183
-                )}
184
-                <div className="clearfix" />
185
-              </div>
186
-            )}
153
+                  }
154
+                  return (
155
+                    <div
156
+                      className="comment-item-image-wrapper"
157
+                      key={index}
158
+                      onClick={() => {
159
+                        let i = index;
160
+                        if (needClear) {
161
+                          if (index > 3) {
162
+                            i -= 1;
163
+                          }
164
+                          if (index > 7) {
165
+                            i -= 1;
166
+                          }
167
+                        }
168
+                        this.showPreviewer(i);
169
+                      }}
170
+                    >
171
+                      <div
172
+                        style={{ backgroundImage: `url(${item})` }}
173
+                        className="comment-img-thumbnail"
174
+                      />
175
+                      {/* <img src={item} alt={item} className="comment-img" /> */}
176
+                    </div>
177
+                  );
178
+                })}
179
+              {this.state.showPreviewer && (
180
+                <ImagePreviewer
181
+                  list={imageList}
182
+                  index={this.state.previewerIndex}
183
+                  onFold={this.hidePreviewer}
184
+                />
185
+              )}
186
+              <div className="clearfix" />
187
+            </div>
188
+          )}
187 189
           <div className="comment-item-bottom">
188 190
             {content.reply_count ? (
189 191
               <div>
190 192
                 <a className="comment-item-bottom-left" onClick={onShowReply}>
191
-                  {content.reply_count} 条回复
193
+                  {/* {content.reply_count} 条回复 */}
194
+                  {intl.get("reply.totalReply", { total: content.reply_count })}
192 195
                   {showReply ? <Icon type="up" /> : <Icon type="down" />}
193 196
                 </a>
194 197
               </div>
195 198
             ) : null}
196 199
             {app.userId === content.user_id && (
197 200
               <Popconfirm
198
-                title="确定要删除吗?"
201
+                // title="确定要删除吗?"
202
+                title={intl.get("popConfirm.title")}
199 203
                 onConfirm={() => {
200 204
                   if (replyId) {
201 205
                     app.sDeleteReply(content.id, commentId);
@@ -203,17 +207,19 @@ class CommentItem extends Component {
203 207
                   }
204 208
                   app.sDeleteComment(content.id);
205 209
                 }}
206
-                okText="确定"
207
-                cancelText="取消"
210
+                okText={intl.get("popConfirm.ok")}
211
+                cancelText={intl.get("popConfirm.cancel")}
208 212
               >
209
-                <a className="comment-item-bottom-right">&nbsp; 删除</a>
213
+                <a className="comment-item-bottom-right">
214
+                  &nbsp; {intl.get("popConfirm.delete")}
215
+                </a>
210 216
               </Popconfirm>
211 217
             )}
212 218
             <a
213 219
               onClick={this.handleToggleInput}
214 220
               className="comment-item-bottom-right"
215 221
             >
216
-              &nbsp; 回复
222
+              &nbsp; {intl.get("comment.reply")}
217 223
             </a>
218 224
             <div
219 225
               className="comment-item-bottom-right"

+ 2
- 1
src/components/Editor/Upload.js 查看文件

@@ -2,6 +2,7 @@ import React from "react";
2 2
 import { Upload, Icon, Modal, message } from "antd";
3 3
 import dayjs from "dayjs";
4 4
 import shortid from "shortid";
5
+import intl from "react-intl-universal";
5 6
 import {
6 7
   OSS_ENDPOINT,
7 8
   OSS_BUCKET,
@@ -106,7 +107,7 @@ class App extends React.Component {
106 107
     const uploadButton = (
107 108
       <div>
108 109
         <Icon type="plus" />
109
-        <div className="ant-upload-text">上传</div>
110
+        <div className="ant-upload-text">{intl.get("editor.uploadBtn")}</div>
110 111
       </div>
111 112
     );
112 113
     return (

+ 18
- 8
src/components/Editor/index.js 查看文件

@@ -2,6 +2,7 @@ import React from "react";
2 2
 import PropTypes from "prop-types";
3 3
 import { Icon, Button, Popover, Input, message } from "antd";
4 4
 import classnames from "classnames";
5
+import intl from "react-intl-universal";
5 6
 import { OSS_LINK } from "../../constant";
6 7
 import { isFunction } from "../../helper";
7 8
 import Upload from "./Upload";
@@ -119,7 +120,8 @@ class Editor extends React.Component {
119 120
     const { maxLength } = this.props;
120 121
     let { value, fileMap, fileList } = this.state;
121 122
     if (value.length > maxLength) {
122
-      message.error(`字数不得超过${maxLength}字`);
123
+      // message.error(`字数不得超过${maxLength}字`);
124
+      message.error(intl.get("editor.maxLength", { maxLength }));
123 125
       return;
124 126
     }
125 127
     const files = [];
@@ -166,13 +168,13 @@ class Editor extends React.Component {
166 168
   render() {
167 169
     const {
168 170
       value,
169
-      placeholder,
171
+      // placeholder,
170 172
       rows,
171 173
       showEmoji,
172 174
       showUpload,
173 175
       closeUploadWhenBlur,
174 176
       maxUpload,
175
-      btnSubmitText,
177
+      // btnSubmitText,
176 178
       btnLoading,
177 179
       btnDisabled,
178 180
       button,
@@ -181,6 +183,8 @@ class Editor extends React.Component {
181 183
       maxLength,
182 184
       autoFocus
183 185
     } = this.props;
186
+    let placeholder = this.props.placeholder || intl.get("editor.placeholder");
187
+    let btnSubmitText = this.props.placeholder || intl.get("editor.SubmitBtn");
184 188
     const handleSubmit = this.handleSubmit;
185 189
     const disabledSubmit =
186 190
       btnDisabled ||
@@ -194,7 +198,11 @@ class Editor extends React.Component {
194 198
             "comment-editor-toolbar-error": inputValue.length > maxLength
195 199
           })}
196 200
         >
197
-          已输入 {inputValue.length} / {maxLength} 字
201
+          {intl.get("editor.alreadyEntered", {
202
+            count: inputValue.length,
203
+            maxLength
204
+          })}
205
+          {/* 已输入 {inputValue.length} / {maxLength} 字 */}
198 206
         </div>
199 207
         <div className="comment-editor">
200 208
           <TextArea
@@ -268,10 +276,12 @@ class Editor extends React.Component {
268 276
                   title={
269 277
                     <div style={{ margin: "5px auto" }}>
270 278
                       <span>
271
-                        上传图片
279
+                        {intl.get("editor.uploadTip")}
272 280
                         {maxUpload >= 2 ? (
273 281
                           <span style={{ color: "#666", fontWeight: 400 }}>
274
-                            (您还能上传{maxUpload - this.state.fileList.length}张图片)
282
+                            {intl.get("editor.uploadCount", {
283
+                              count: maxUpload - this.state.fileList.length
284
+                            })}
275 285
                           </span>
276 286
                         ) : null}
277 287
                       </span>
@@ -350,12 +360,12 @@ Editor.propTypes = {
350 360
 
351 361
 Editor.defaultProps = {
352 362
   rows: 5,
353
-  placeholder: "说点什么吧...",
363
+  // placeholder: "说点什么吧",
354 364
   showEmoji: true,
355 365
   showUpload: true,
356 366
   closeUploadWhenBlur: false,
357 367
   maxUpload: 1,
358
-  btnSubmitText: "发表",
368
+  // btnSubmitText: "发表",
359 369
   btnLoading: false,
360 370
   btnDisabled: false,
361 371
   showError: true,

+ 3
- 2
src/components/ImagePreviewer/ImagePreviewer.jsx 查看文件

@@ -1,6 +1,7 @@
1 1
 import React from "react";
2 2
 import classnames from "classnames";
3 3
 import { Icon, Spin } from "antd";
4
+import intl from "react-intl-universal";
4 5
 
5 6
 import "./ImagePreviewer.less";
6 7
 // import "./ImagePreviewer.css";
@@ -104,10 +105,10 @@ export default class ImagePreviewer extends React.Component {
104 105
         <div className="toolbar">
105 106
           <span className="button" onClick={onFold}>
106 107
             <Icon type="to-top" />
107
-            收起
108
+            {intl.get("picture.collapse")}
108 109
           </span>
109 110
           <span className="button" onClick={this.onOrigin}>
110
-            <Icon type="search" /> 查看原图
111
+            <Icon type="search" /> {intl.get("picture.viewOriginal")}
111 112
           </span>
112 113
           {/* <span className="button" onClick={this.rotateRight}>
113 114
                         <Icon type="reload" /> 向右旋转

+ 29
- 0
src/lang/en-US.js 查看文件

@@ -0,0 +1,29 @@
1
+const USdata = {
2
+  "editor.alreadyEntered": "already entered {count}/{maxLength}",
3
+  "editor.placeholder": "say...",
4
+  "editor.maxLength": "Input number must < {maxLength}",
5
+  "editor.SubmitBtn": "Submit",
6
+  "editor.uploadTip": "Upload Pictures",
7
+  "editor.uploadCount": "(You can also upload {count} images)",
8
+  "editor.uploadBtn": "upload",
9
+
10
+  "comment.tourist": "tourist",
11
+  "comment.totalComment":
12
+    "total {total, plural, =1 {one comment} other {# comments}}",
13
+  "comment.reply": "reply",
14
+  "comment.moreComment": "More",
15
+
16
+  "reply.totalReply": "{total, plural, =1 {one reply} other {# replies}}",
17
+  "reply.moreReply": "More",
18
+  "reply.collapse": "clloasp reply",
19
+
20
+  "picture.collapse": "collapse",
21
+  "picture.viewOriginal": "view original picture",
22
+
23
+  "popConfirm.title": "Sure?",
24
+  "popConfirm.ok": "Ok",
25
+  "popConfirm.cancel": "Cancel",
26
+  "popConfirm.delete": "Delete"
27
+};
28
+
29
+export default USdata;

+ 0
- 21
src/lang/en-US.json 查看文件

@@ -1,21 +0,0 @@
1
-{
2
-  "editor.alreadyEntered": "已输入{count}/140字",
3
-  "editor.placeholder": "say...",
4
-  "editor.SubmitBtn": "Submit",
5
-  "editor.uploadTip": "上传图片",
6
-  "editor.uploadCount": "(您还能上传{count}张图片)",
7
-  "editor.uploadBtn": "upload",
8
-
9
-  "comment.totalComment": "共{total}条评论",
10
-  "comment.reply": "reply",
11
-  "comment.moreComment": "More",
12
-
13
-  "reply.totalReply": "{total}条回复",
14
-  "reply.moreReply": "More",
15
-  "reply.collapse": "收起回复",
16
-
17
-  "popConfirm.title": "Sure?",
18
-  "popConfirm.ok": "Ok",
19
-  "popConfirm.cancel": "Cancel",
20
-  "popConfirm.delete": "Delete"
21
-}

src/lang/zh-CN.json → src/lang/zh-CN.js 查看文件

@@ -1,11 +1,13 @@
1
-{
1
+const CNdata = {
2 2
   "editor.alreadyEntered": "已输入{count}/140字",
3 3
   "editor.placeholder": "说点什么吧...",
4
+  "editor.maxLength": "字数不过超过{maxLength}字",
4 5
   "editor.SubmitBtn": "发表",
5 6
   "editor.uploadTip": "上传图片",
6 7
   "editor.uploadCount": "(您还能上传{count}张图片)",
7 8
   "editor.uploadBtn": "上传",
8 9
 
10
+  "comment.tourist": "游客",
9 11
   "comment.totalComment": "共{total}条评论",
10 12
   "comment.reply": "回复",
11 13
   "comment.moreComment": "查看更多评论",
@@ -14,8 +16,13 @@
14 16
   "reply.moreReply": "查看更多回复",
15 17
   "reply.collapse": "收起回复",
16 18
 
19
+  "picture.collapse": "收起",
20
+  "picture.viewOriginal": "查看原图",
21
+
17 22
   "popConfirm.title": "确定要删除吗",
18 23
   "popConfirm.ok": "确定",
19 24
   "popConfirm.cancel": "取消",
20 25
   "popConfirm.delete": "删除"
21
-}
26
+};
27
+
28
+export default CNdata;