Procházet zdrojové kódy

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

node před 5 roky
rodič
revize
fb5bdd77a4

+ 14
- 10
src/App.js Zobrazit soubor

11
 import Editor from "./components/Editor";
11
 import Editor from "./components/Editor";
12
 import RenderText from "./components/RenderText";
12
 import RenderText from "./components/RenderText";
13
 import lang from "./lang";
13
 import lang from "./lang";
14
+import USdata from "./lang/en-US.js";
15
+import CNdata from "./lang/zh-CN.js";
14
 import "./App.css";
16
 import "./App.css";
15
 // import styles from "./App.module.css";
17
 // import styles from "./App.module.css";
16
 
18
 
28
   }
30
   }
29
 ];
31
 ];
30
 
32
 
33
+const LOCALES = {
34
+  "zh-CN": CNdata,
35
+  "en-US": USdata
36
+};
37
+
31
 class App extends Component {
38
 class App extends Component {
32
   constructor(props) {
39
   constructor(props) {
33
     super(props);
40
     super(props);
88
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
95
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
89
       ? currentLocale
96
       ? currentLocale
90
       : "zh-CN";
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
       .then(() => {
106
       .then(() => {
103
         this.setState({ initDone: true });
107
         this.setState({ initDone: true });

+ 10
- 10
src/components/CommentBox/index.js Zobrazit soubor

1
 import React, { Component } from "react";
1
 import React, { Component } from "react";
2
 import PropTypes from "prop-types";
2
 import PropTypes from "prop-types";
3
 import { Icon } from "antd";
3
 import { Icon } from "antd";
4
+import intl from "react-intl-universal";
4
 import Comment from "../../Comment";
5
 import Comment from "../../Comment";
5
 import ContentItem from "./../ContentItem";
6
 import ContentItem from "./../ContentItem";
6
 import "./index.css";
7
 import "./index.css";
60
                   action="replyToReply" // 回复的回复
61
                   action="replyToReply" // 回复的回复
61
                 />,
62
                 />,
62
                 <div className="comment-more-box" key="show_more_button">
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
                   <a
73
                   <a
74
                     style={{ float: "right" }}
74
                     style={{ float: "right" }}
75
                     onClick={this.handleToggleReply}
75
                     onClick={this.handleToggleReply}
76
                   >
76
                   >
77
-                    <Icon type="up" /> 收起回复
77
+                    <Icon type="up" /> {intl.get("reply.collapse")}
78
                   </a>
78
                   </a>
79
                 </div>
79
                 </div>
80
               ];
80
               ];

+ 4
- 2
src/components/CommentList/index.js Zobrazit soubor

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

+ 58
- 52
src/components/ContentItem/index.js Zobrazit soubor

3
 import { Avatar, Icon, Tooltip, Popconfirm } from "antd";
3
 import { Avatar, Icon, Tooltip, Popconfirm } from "antd";
4
 import dayjs from "dayjs";
4
 import dayjs from "dayjs";
5
 import "dayjs/locale/zh-cn";
5
 import "dayjs/locale/zh-cn";
6
+// import 'dayjs/locale/es';
6
 import relativeTime from "dayjs/plugin/relativeTime";
7
 import relativeTime from "dayjs/plugin/relativeTime";
8
+import intl from "react-intl-universal";
7
 import Comment from "../../Comment";
9
 import Comment from "../../Comment";
8
 import CommentInput from "../CommentInput";
10
 import CommentInput from "../CommentInput";
9
 import avatar from "../../avatar";
11
 import avatar from "../../avatar";
12
 import "./index.css";
14
 import "./index.css";
13
 import ImagePreviewer from "../ImagePreviewer/ImagePreviewer";
15
 import ImagePreviewer from "../ImagePreviewer/ImagePreviewer";
14
 
16
 
15
-dayjs.locale("zh-cn");
17
+// dayjs.locale("zh-cn");
16
 dayjs.extend(relativeTime);
18
 dayjs.extend(relativeTime);
17
 
19
 
18
 class CommentItem extends Component {
20
 class CommentItem extends Component {
115
             {/* <a href={`/${content.user_id}`}>
117
             {/* <a href={`/${content.user_id}`}>
116
               {content.user_name || "暂无昵称"}
118
               {content.user_name || "暂无昵称"}
117
             </a> */}
119
             </a> */}
118
-            <strong>{content.user_name || "游客"}</strong>
120
+            <strong>{content.user_name || intl.get("comment.tourist")}</strong>
119
             <span style={{ marginLeft: 10 }}>
121
             <span style={{ marginLeft: 10 }}>
120
               <Tooltip
122
               <Tooltip
121
                 placement="top"
123
                 placement="top"
124
                 )}
126
                 )}
125
               >
127
               >
126
                 {dayjs(content.created * 1000).fromNow()}
128
                 {dayjs(content.created * 1000).fromNow()}
129
+                {/* {dayjs(content.created * 1000).locale('zh-cn').fromNow()} */}
127
               </Tooltip>
130
               </Tooltip>
128
             </span>
131
             </span>
129
           </div>
132
           </div>
136
             }}
139
             }}
137
           />
140
           />
138
           {// image为空时不渲染comment-item-image
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
                     return (
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
                         {/* <img src={item} alt={item} className="comment-img" /> */}
150
                         {/* <img src={item} alt={item} className="comment-img" /> */}
174
                       </div>
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
           <div className="comment-item-bottom">
189
           <div className="comment-item-bottom">
188
             {content.reply_count ? (
190
             {content.reply_count ? (
189
               <div>
191
               <div>
190
                 <a className="comment-item-bottom-left" onClick={onShowReply}>
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
                   {showReply ? <Icon type="up" /> : <Icon type="down" />}
195
                   {showReply ? <Icon type="up" /> : <Icon type="down" />}
193
                 </a>
196
                 </a>
194
               </div>
197
               </div>
195
             ) : null}
198
             ) : null}
196
             {app.userId === content.user_id && (
199
             {app.userId === content.user_id && (
197
               <Popconfirm
200
               <Popconfirm
198
-                title="确定要删除吗?"
201
+                // title="确定要删除吗?"
202
+                title={intl.get("popConfirm.title")}
199
                 onConfirm={() => {
203
                 onConfirm={() => {
200
                   if (replyId) {
204
                   if (replyId) {
201
                     app.sDeleteReply(content.id, commentId);
205
                     app.sDeleteReply(content.id, commentId);
203
                   }
207
                   }
204
                   app.sDeleteComment(content.id);
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
               </Popconfirm>
216
               </Popconfirm>
211
             )}
217
             )}
212
             <a
218
             <a
213
               onClick={this.handleToggleInput}
219
               onClick={this.handleToggleInput}
214
               className="comment-item-bottom-right"
220
               className="comment-item-bottom-right"
215
             >
221
             >
216
-              &nbsp; 回复
222
+              &nbsp; {intl.get("comment.reply")}
217
             </a>
223
             </a>
218
             <div
224
             <div
219
               className="comment-item-bottom-right"
225
               className="comment-item-bottom-right"

+ 2
- 1
src/components/Editor/Upload.js Zobrazit soubor

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

+ 18
- 8
src/components/Editor/index.js Zobrazit soubor

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

+ 3
- 2
src/components/ImagePreviewer/ImagePreviewer.jsx Zobrazit soubor

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

+ 29
- 0
src/lang/en-US.js Zobrazit soubor

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 Zobrazit soubor

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 Zobrazit soubor

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