Skip to content

Commit 11330cc

Browse files
committed
refactor: i18n
mod: code review mod: code review mod: code review mod: code review mod: code review mod: update i18n mod: update rule validator mod: update version
1 parent 57f885f commit 11330cc

File tree

77 files changed

+353
-278
lines changed

Some content is hidden

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

77 files changed

+353
-278
lines changed

.npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
registry=https://registry.npm.taobao.org
1+
# registry=https://registry.npm.taobao.org

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import errorImg from '@app/static/images/errorBoundary.png';
3-
import intl from 'react-intl-universal';
3+
import { I18nContext } 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';
@@ -17,6 +17,7 @@ class ErrorBoundary extends React.PureComponent<IProps, IState> {
1717
errInfo: null,
1818
};
1919
}
20+
static contextType = I18nContext;
2021
componentDidCatch(error) {
2122
this.setState({
2223
errInfo: error?.stack?.toString(),
@@ -31,11 +32,13 @@ class ErrorBoundary extends React.PureComponent<IProps, IState> {
3132
}
3233

3334
handleCopy = () => {
35+
const { intl } = this.context;
3436
message.success(intl.get('common.copySuccess'));
3537
};
3638

3739
render() {
3840
const { errInfo } = this.state;
41+
const { intl } = this.context;
3942
if(!errInfo) return this.props.children;
4043
return <div className={styles.errPage}>
4144
<img src={errorImg} className={styles.errImg} />

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);

app/pages/Console/OutputBox/ForceGraph/DisplayPanel/ExpandForm/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Tabs } from 'antd';
22
import React, { useEffect, useState } from 'react';
3-
import intl from 'react-intl-universal';
43
import { LinkObject, NodeObject } from '@vesoft-inc/force-graph';
4+
import { useI18n } from '@vesoft-inc/i18n';
55
import ExpandItem from '../ExpandItem';
66
import styles from './index.module.less';
77

@@ -16,7 +16,7 @@ interface IProps {
1616
const DisplayComponent = (props: IProps) => {
1717
const [tab, setTab] = useState<any>('nodes');
1818
const { data, spaceVidType } = props;
19-
19+
const { intl } = useI18n();
2020
const { nodes, links } = data;
2121
const [list, setList] = useState<{
2222
nodes: NodeObject[];

app/pages/Console/OutputBox/ForceGraph/DisplayPanel/ExpandItem/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useState } from 'react';
2-
import intl from 'react-intl-universal';
32

43
import Icon from '@app/components/Icon';
54
import { convertBigNumberToString, removeNullCharacters } from '@app/utils/function';
65
import cls from 'classnames';
6+
import { useI18n } from '@vesoft-inc/i18n';
77
import styles from './index.module.less';
88

99
interface IProps {
@@ -54,6 +54,7 @@ const RowItem = (props: IProps) => {
5454
if(!data) {
5555
return null;
5656
}
57+
const { intl } = useI18n();
5758
const [dataUnfolded, setDataUnfoldedStatus] = useState(index === 0);
5859
const needUnfoldMore = data.length > EXPAND_NUM;
5960
const [hasUnfoldAll, setUnfoldAllStatus] = useState(false);

app/pages/Console/OutputBox/ForceGraph/Menu/ColorChangeBtn/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import intl from 'react-intl-universal';
32
import { observer } from 'mobx-react-lite';
43
import MenuButton from '@app/components/Button';
54
import { uniq } from 'lodash';
65
import { GraphStore } from '@app/stores/graph';
6+
import { useI18n } from '@vesoft-inc/i18n';
77
import NodeStyleSetBtn from '../NodeStyleSetBtn';
88

99
interface IProps {
@@ -15,7 +15,7 @@ const DEFAULT_CONFIG = ['#ece9e8'];
1515
const ColorChangeBtn: React.FC<IProps> = (props: IProps) => {
1616
const { onClose, graph } = props;
1717
const { nodesSelected } = graph;
18-
18+
const { intl } = useI18n();
1919
const handleUpdateVertex = (value, nodesSelected, type) => {
2020
nodesSelected.forEach(vertex => {
2121
vertex[type] = value;

0 commit comments

Comments
 (0)