Skip to content

Commit 40e5757

Browse files
authored
refactor: i18n (#352)
* refactor: i18n * mod: update package version
1 parent 57f885f commit 40e5757

File tree

76 files changed

+379
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+379
-300
lines changed

app/components/CSVPreviewLink/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, Popover, Table } from 'antd';
22
import { } from 'antd/lib/button';
33
import React, { useState } from 'react';
4-
import intl from 'react-intl-universal';
4+
import { useI18n } from '@vesoft-inc/i18n';
55
import { v4 as uuidv4 } from 'uuid';
66
import cls from 'classnames';
77
import styles from './index.module.less';
@@ -17,6 +17,7 @@ interface IProps {
1717
const CSVPreviewLink = (props: IProps) => {
1818
const { onMapping, file: { content }, children, btnType, selected } = props;
1919
const [visible, setVisible] = useState(false);
20+
const { intl } = useI18n();
2021
const handleLinkClick = e => {
2122
e.stopPropagation();
2223
setVisible(true);

app/components/ErrorBoundary/index.tsx

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
1+
import React, { useCallback } from 'react';
22
import errorImg from '@app/static/images/errorBoundary.png';
3-
import intl from 'react-intl-universal';
3+
import { I18nContext, useI18n } from '@vesoft-inc/i18n';
44
import { CopyToClipboard } from 'react-copy-to-clipboard';
55
import { Button, message } from 'antd';
66
import { withRouter, RouteComponentProps } from 'react-router-dom';
@@ -10,13 +10,41 @@ interface IProps extends RouteComponentProps {}
1010
interface IState {
1111
errInfo: string;
1212
}
13+
14+
function ErrorPanel(props: { errInfo: string }) {
15+
const { errInfo } = props;
16+
const { intl } = useI18n();
17+
const handleCopy = useCallback(() => {
18+
message.success(intl.get('common.copySuccess'));
19+
}, []);
20+
return <div className={styles.errPage}>
21+
<img src={errorImg} className={styles.errImg} />
22+
<p className={styles.errText}>{intl.get('warning.crashPage')}</p>
23+
<p className={styles.errTip}>{intl.get('warning.crashPageTip')}</p>
24+
<div className={styles.btns}>
25+
<Button type="primary" onClick={() => window.location.reload()}>{intl.get('warning.refreshPage')}</Button>
26+
<Button onClick={() => window.open(intl.get('link.forumHref'), '_blank')}>{intl.get('warning.contactStaff')}</Button>
27+
</div>
28+
<div className={styles.errContainer}>
29+
<div className={styles.header}>
30+
<span>{intl.get('warning.errorMessage')}</span>
31+
<CopyToClipboard key={1} text={errInfo} onCopy={handleCopy}>
32+
<Button>{intl.get('common.copy')}</Button>
33+
</CopyToClipboard>
34+
</div>
35+
<p className={styles.errMsg}>{errInfo.toString()}</p>
36+
</div>
37+
</div>;
38+
}
39+
1340
class ErrorBoundary extends React.PureComponent<IProps, IState> {
1441
constructor(props) {
1542
super(props);
1643
this.state = {
1744
errInfo: null,
1845
};
1946
}
47+
static contextType = I18nContext;
2048
componentDidCatch(error) {
2149
this.setState({
2250
errInfo: error?.stack?.toString(),
@@ -30,31 +58,10 @@ class ErrorBoundary extends React.PureComponent<IProps, IState> {
3058
}
3159
}
3260

33-
handleCopy = () => {
34-
message.success(intl.get('common.copySuccess'));
35-
};
36-
3761
render() {
3862
const { errInfo } = this.state;
3963
if(!errInfo) return this.props.children;
40-
return <div className={styles.errPage}>
41-
<img src={errorImg} className={styles.errImg} />
42-
<p className={styles.errText}>{intl.get('warning.crashPage')}</p>
43-
<p className={styles.errTip}>{intl.get('warning.crashPageTip')}</p>
44-
<div className={styles.btns}>
45-
<Button type="primary" onClick={() => window.location.reload()}>{intl.get('warning.refreshPage')}</Button>
46-
<Button onClick={() => window.open(intl.get('link.forumHref'), '_blank')}>{intl.get('warning.contactStaff')}</Button>
47-
</div>
48-
<div className={styles.errContainer}>
49-
<div className={styles.header}>
50-
<span>{intl.get('warning.errorMessage')}</span>
51-
<CopyToClipboard key={1} text={errInfo} onCopy={this.handleCopy}>
52-
<Button>{intl.get('common.copy')}</Button>
53-
</CopyToClipboard>
54-
</div>
55-
<p className={styles.errMsg}>{errInfo.toString()}</p>
56-
</div>
57-
</div>;
64+
return <ErrorPanel errInfo={errInfo} />;
5865
}
5966
}
6067

app/components/GQLCodeMirror/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Collapse } from 'antd';
22
import React from 'react';
3-
import intl from 'react-intl-universal';
3+
import { useI18n } from '@vesoft-inc/i18n';
44

55
import CodeMirror from '@app/components/CodeMirror';
66

@@ -17,6 +17,7 @@ const GQLCodeMirror = (props: { currentGQL: string; option?: IOptions }) => {
1717
readOnly: true,
1818
...props.option,
1919
};
20+
const { intl } = useI18n();
2021
return (
2122
<Collapse className={styles.exportGql}>
2223
<Panel header={intl.get('common.exportNGQL')} key="ngql">
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,67 @@
1+
import React from 'react';
2+
import { Translation } from '@vesoft-inc/i18n';
13
import { MAX_COMMENT_BYTES, POSITIVE_INTEGER_REGEX } from '@app/utils/constant';
24
import { getByteLength } from '@app/utils/function';
3-
import intl from 'react-intl-universal';
45

56
export const hostRulesFn = () => [
67
{
78
required: true,
8-
message: intl.get('formRules.hostRequired'),
9+
message: <Translation>
10+
{intl => intl.get('formRules.hostRequired')}
11+
</Translation>,
912
},
1013
];
1114

1215
export const usernameRulesFn = () => [
1316
{
1417
required: true,
15-
message: intl.get('formRules.usernameRequired'),
18+
message: <Translation>
19+
{intl => intl.get('formRules.usernameRequired')}
20+
</Translation>,
1621
},
1722
];
1823

1924
export const passwordRulesFn = () => [
2025
{
2126
required: true,
22-
message: intl.get('formRules.passwordRequired'),
27+
message: <Translation>
28+
{intl => intl.get('formRules.passwordRequired')}
29+
</Translation>,
2330
},
2431
];
2532

2633
export const nameRulesFn = () => [
2734
{
2835
required: true,
29-
message: intl.get('formRules.nameRequired'),
30-
},
36+
message: <Translation>
37+
{intl => intl.get('formRules.nameRequired')}
38+
</Translation>,
39+
}
3140
];
3241

3342
export const numberRulesFn = () => [
3443
{
3544
pattern: POSITIVE_INTEGER_REGEX,
36-
message: intl.get('formRules.numberRequired'),
45+
message: <Translation>
46+
{intl => intl.get('formRules.numberRequired')}
47+
</Translation>,
3748
},
3849
];
3950

4051
export const replicaRulesFn = (activeMachineNum) => [
4152
{
4253
pattern: POSITIVE_INTEGER_REGEX,
43-
message: intl.get('formRules.numberRequired'),
54+
message: <Translation>
55+
{intl => intl.get('formRules.numberRequired')}
56+
</Translation>,
4457
},
4558
{
4659
validator(_rule, value, callback) {
4760
if (value && Number(value) > activeMachineNum) {
4861
callback(
49-
intl.get('formRules.replicaLimit', { number: activeMachineNum }),
62+
<Translation>
63+
{intl => intl.get('formRules.replicaLimit', { number: activeMachineNum })}
64+
</Translation>
5065
);
5166
}
5267
callback();
@@ -60,6 +75,8 @@ export const stringByteRulesFn = () => [
6075
if (byteLength <= MAX_COMMENT_BYTES) {
6176
return Promise.resolve();
6277
}
63-
return Promise.reject(intl.get('formRules.maxBytes', { max: MAX_COMMENT_BYTES }));
78+
return Promise.reject(<Translation>
79+
{intl => intl.get('formRules.maxBytes', { max: MAX_COMMENT_BYTES })}
80+
</Translation>);
6481
} }
6582
];

app/context/LanguageContext.ts

-14
This file was deleted.

app/context/index.ts

-5
This file was deleted.

app/index.tsx

+6-30
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { hot } from 'react-hot-loader/root';
22
import { Spin, message } from 'antd';
3-
import React, { Suspense, lazy, useState, useEffect } from 'react';
3+
import React, { Suspense, lazy, useEffect } from 'react';
44
import ReactDom from 'react-dom';
55
import { Route, BrowserRouter as Router, Switch, useHistory } from 'react-router-dom';
66
import { observer } from 'mobx-react-lite';
77
import dayjs from 'dayjs';
8-
import intl from 'react-intl-universal';
98
import duration from 'dayjs/plugin/duration';
109
import Cookie from 'js-cookie';
1110
import { trackPageView } from '@app/utils/stat';
11+
import { I18nProvider, getI18n } from '@vesoft-inc/i18n';
1212
import { INTL_LOCALES } from '@app/config/constants';
13-
import { LanguageContext } from '@app/context';
1413
import { useStore } from '@app/stores';
1514
import AuthorizedRoute from './AuthorizedRoute';
1615
import rootStore, { StoreProvider } from './stores';
@@ -24,44 +23,21 @@ message.config({
2423
maxCount: 1,
2524
});
2625
const defaultLanguage = Cookie.get('lang') || document.documentElement.getAttribute('lang');
27-
intl.init({
28-
currentLocale: defaultLanguage || 'EN_US',
29-
locales: INTL_LOCALES,
30-
});
31-
32-
26+
const { initI18n } = getI18n();
27+
initI18n(defaultLanguage, INTL_LOCALES);
3328
const PageRoot = observer(() => {
3429
const { global: { version } } = useStore();
35-
const [currentLocale, setCurrentLocale] = useState(
36-
defaultLanguage || 'EN-US',
37-
);
38-
39-
const toggleLanguage = (locale: string) => {
40-
Cookie.set('lang', locale);
41-
setCurrentLocale(locale);
42-
intl
43-
.init({
44-
currentLocale: locale,
45-
locales: INTL_LOCALES,
46-
});
47-
};
48-
4930
useEffect(() => {
5031
trackPageView(`Studio/v${version}`);
5132
}, []);
5233

5334
return (
5435
<StoreProvider value={rootStore}>
55-
<LanguageContext.Provider
56-
value={{
57-
currentLocale,
58-
toggleLanguage,
59-
}}
60-
>
36+
<I18nProvider locales={INTL_LOCALES}>
6137
<Router>
6238
<App />
6339
</Router>
64-
</LanguageContext.Provider>
40+
</I18nProvider>
6541
</StoreProvider>
6642
);
6743
});

app/interfaces/sketch.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ISchemaEnum } from './schema';
44
export interface IProperty {
55
name: string;
66
type: string;
7-
fixedLength: string;
7+
fixedLength?: string;
88
}
99
export interface ISketchNode extends VEditorNode {
1010
uuid?: string;
@@ -16,6 +16,7 @@ export interface ISketchNode extends VEditorNode {
1616
comment?: string;
1717
invalid: boolean;
1818
strokeDasharray?: string;
19+
vid?: string;
1920
}
2021

2122
export interface ISketchEdge extends VEditorLine {

app/pages/Console/CypherParameterBox.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Tooltip } from 'antd';
22
import React, { useState } from 'react';
3-
import intl from 'react-intl-universal';
3+
import { useI18n } from '@vesoft-inc/i18n';
44
import Icon from '@app/components/Icon';
55
import styles from './index.module.less';
66

@@ -11,7 +11,7 @@ interface IProps {
1111
const CypherParameterBox = (props: IProps) => {
1212
const { data, onSelect } = props;
1313
const [paramVisible, setParamVisible] = useState(false);
14-
14+
const { intl } = useI18n();
1515
if(!paramVisible) {
1616
return <div className={styles.btnOpenParam} onClick={() => setParamVisible(true)}>
1717
<Icon type="icon-studio-btn-down" />

app/pages/Console/ExportModal.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Button, Form, Input, Modal, Radio, Select } from 'antd';
22
import React from 'react';
3-
import intl from 'react-intl-universal';
43
import { observer } from 'mobx-react-lite';
54
import { useStore } from '@app/stores';
65

6+
import { useI18n } from '@vesoft-inc/i18n';
77
import styles from './index.module.less';
88
const Option = Select.Option;
99

@@ -26,6 +26,7 @@ const ExportModal = (props: IProps) => {
2626
const { data, visible, onClose, onExplorer } = props;
2727
const { schema: { currentSpace } } = useStore();
2828
const { headers, tables } = data;
29+
const { intl } = useI18n();
2930
const handleExport = (values) => {
3031
const { type, vertexId, srcId, dstId, edgeType, rank } = values;
3132
const vertexes =

app/pages/Console/FavoriteBtn.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Button, List, Modal, Tooltip, Popconfirm } from 'antd';
22
import React, { useCallback, useState } from 'react';
3-
import intl from 'react-intl-universal';
43
import { observer } from 'mobx-react-lite';
54
import Icon from '@app/components/Icon';
65
import { useStore } from '@app/stores';
76

7+
import { useI18n } from '@vesoft-inc/i18n';
88
import styles from './index.module.less';
99

1010

@@ -15,7 +15,7 @@ const FavoriteBtn = (props: IProps) => {
1515
const { onGqlSelect } = props;
1616
const { console } = useStore();
1717
const [visible, setVisible] = useState(false);
18-
18+
const { intl } = useI18n();
1919
const handleClear = useCallback(async () => {
2020
const { favorites, deleteFavorite, getFavoriteList } = console;
2121
if(!favorites.length) {

app/pages/Console/HistoryBtn.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, List, Modal, Tooltip } from 'antd';
22
import React, { useState } from 'react';
3-
import intl from 'react-intl-universal';
43
import Icon from '@app/components/Icon';
4+
import { useI18n } from '@vesoft-inc/i18n';
55
import styles from './index.module.less';
66

77

@@ -12,6 +12,7 @@ const HistoryBtn = (props: IProps) => {
1212
const { onGqlSelect } = props;
1313
const [visible, setVisible] = useState(false);
1414
const [data, setData] = useState([]);
15+
const { intl } = useI18n();
1516
const handleView = () => {
1617
const data = getHistory();
1718
setData(data);

0 commit comments

Comments
 (0)