Skip to content

Commit

Permalink
chore: tweak i18n (#90)
Browse files Browse the repository at this point in the history
* chore: remove react-intl

* feat: add i18n keys
  • Loading branch information
xudafeng authored Nov 28, 2022
1 parent 1d321a2 commit 3d6f80e
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 280 deletions.
12 changes: 12 additions & 0 deletions i18n.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const path = require('path');

module.exports = {
srcDirs: [
'view/src/**/*{.js,.jsx,.ts,.tsx}',
],
distDir: path.resolve(__dirname, 'view/src/locale'),
tokenName: '__i18n',
debug: true,
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"autod-egg": "^1.0.0",
"concurrently": "4.0.1",
"debug": "^3.1.0",
"easy-i18n-cli": "1",
"egg-bin": "^4.3.5",
"egg-mock": "^3.14.0",
"eslint": "^4.11.0",
Expand All @@ -45,6 +46,7 @@
"cov": "npm run db:prepare:test && egg-bin cov",
"lint": "eslint . --fix",
"autod": "autod",
"translate": "easy-i18n-cli -c ./i18n.config.js",
"build:docker": "docker build --no-cache --pull -t macacajs/reliable-web .",
"db:prepare:test": "NODE_ENV=test npm run db:migrate:undo:all && NODE_ENV=test npm run db:migrate",
"db:status": "sequelize db:migrate:status",
Expand Down
1 change: 1 addition & 0 deletions view/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/assets
**/coverage
**/reports
view/src/locale/en-US.js
1 change: 0 additions & 1 deletion view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"react-dom": "^16.6.0",
"react-ga": "^2.7.0",
"react-github-button": "0.1.11",
"react-intl": "^2.4.0",
"react-load-script": "^0.0.6",
"react-router-dom": "^4.2.2",
"style-loader": "^0.21.0",
Expand Down
3 changes: 3 additions & 0 deletions view/src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = {
},
},
plugins: ['babel', 'react'],
globals: {
__i18n: true,
},
rules: {
camelcase: 0,
'no-restricted-syntax': 0,
Expand Down
21 changes: 10 additions & 11 deletions view/src/components/BuildsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
SettingOutlined,
RightCircleOutlined,
} from '@ant-design/icons';
import { FormattedMessage } from 'react-intl';

import {
getUuid,
Expand All @@ -26,7 +25,7 @@ export default class BuildsTable extends React.Component {
}

columns = [{
title: <FormattedMessage id="builds.jobName" />,
title: __i18n('项目名'),
dataIndex: 'jobName',
render: (text, record) => {
return (
Expand All @@ -36,7 +35,7 @@ export default class BuildsTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="builds.buildLog" />,
title: __i18n('运行日志'),
width: 100,
render: (text, record) => {
return (record.buildLogUrl
Expand All @@ -45,17 +44,17 @@ export default class BuildsTable extends React.Component {
href={record.buildLogUrl}
target="_blank"
>
<FormattedMessage id="builds.buildLog" />
{__i18n('运行日志')}
</a>
)
: (
<Link to={{ pathname: '/buildlog', search: `?jobName=${record.jobName}&buildNumber=${record.buildNumber}` }}>
<FormattedMessage id="builds.buildLog" />
{__i18n('运行日志')}
</Link>
));
},
}, {
title: <FormattedMessage id="builds.buildNumber" />,
title: __i18n('构建号'),
dataIndex: 'buildNumber',
width: 200,
render: (value, record) => {
Expand All @@ -80,10 +79,10 @@ export default class BuildsTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="builds.platform" />,
title: __i18n('平台'),
dataIndex: 'platform',
}, {
title: <FormattedMessage id="builds.buildEndTime" />,
title: __i18n('完成时间'),
dataIndex: 'buildEndTime',
render: (text, record) => {
return (
Expand All @@ -93,7 +92,7 @@ export default class BuildsTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="buildinfo.pkg.gitBranch" />,
title: __i18n('代码分支'),
dataIndex: 'gitBranch',
width: 240,
render: (text, record) => {
Expand All @@ -104,7 +103,7 @@ export default class BuildsTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="buildinfo.pkg.committer" />,
title: __i18n('提交人'),
dataIndex: 'committer',
width: 120,
render: (text, record) => {
Expand All @@ -115,7 +114,7 @@ export default class BuildsTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="builds.detailInfo" />,
title: __i18n('详情'),
align: 'center',
width: 80,
render: (value, record) => {
Expand Down
4 changes: 2 additions & 2 deletions view/src/components/BuildsTabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Tabs } from 'antd';
import { withRouter } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';

import safeGet from 'lodash/get';

import request from '../util/request';
Expand Down Expand Up @@ -144,7 +144,7 @@ class BuildsTabs extends React.Component {
onTabClick={this.handleTabClick}
style={{ height: 'auto' }}
>
<TabPane tab={<><FormattedMessage id="sidebar.allbuilds" /> ({allJobName.length})</>} key="">
<TabPane tab={<>{__i18n('所有构建')} ({allJobName.length})</>} key="">
</TabPane>
{ listItems }
</Tabs>
Expand Down
8 changes: 4 additions & 4 deletions view/src/components/DingdingSetting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import safeGet from 'lodash/get';
import { uniqBy } from 'lodash';
import { FormattedMessage } from 'react-intl';

import {
Form,
Spin,
Expand Down Expand Up @@ -112,7 +112,7 @@ function DingdingSetting() {
noStyle
>
<Select style={{ width: 88 }}>
<Option value="build"><FormattedMessage id="setting.notification.build" /></Option>
<Option value="build">{__i18n('构建')}</Option>
</Select>
</Form.Item>
)}
Expand Down Expand Up @@ -141,7 +141,7 @@ function DingdingSetting() {
block
icon={<PlusOutlined />}
>
<FormattedMessage id="setting.addDingMessage" />
{__i18n('添加通知')}
</Button>
</Form.Item>
</>
Expand All @@ -154,7 +154,7 @@ function DingdingSetting() {
type="primary"
style={{ width: '100%' }}
>
<FormattedMessage id="setting.submit" />
{__i18n('更新设置')}
</Button>
</Form.Item>
</Form>
Expand Down
5 changes: 2 additions & 3 deletions view/src/components/ExtraTable.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React from 'react';
import { Table } from 'antd';
import { FormattedMessage } from 'react-intl';

import { getUuid } from '../util/index';

const columns = [{
title: <FormattedMessage id="buildinfo.extra.extraName" />,
title: __i18n('项'),
dataIndex: 'extraName',
width: 200,
render: value => { return <span className="itemName">{value}</span>; },
}, {
title: <FormattedMessage id="buildinfo.extra.extraContent" />,
title: __i18n('内容'),
dataIndex: 'extraContent',
render: value => { return <pre>{JSON.stringify(value, null, 2)}</pre>; },
}];
Expand Down
6 changes: 3 additions & 3 deletions view/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
LogoutOutlined,
} from '@ant-design/icons';
import safeGet from 'lodash/get';
import { FormattedMessage } from 'react-intl';

import GitHubButton from 'react-github-button';

import 'react-github-button/assets/style.css';
Expand Down Expand Up @@ -82,15 +82,15 @@ function ContentHeader(props) {
repo="reliable"
/>
</span>
<Tooltip title={<FormattedMessage id="header.document" />}>
<Tooltip title={__i18n('文档')}>
<a
target="_blank"
href={siteConfig.links.document}
>
<BookOutlined />
</a>
</Tooltip>
<Tooltip title={<FormattedMessage id="header.issues" />}>
<Tooltip title={__i18n('问题反馈')}>
<a
target="_blank"
href={siteConfig.links.issues}
Expand Down
9 changes: 4 additions & 5 deletions view/src/components/OneBuildTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import moment from 'moment';
import safeGet from 'lodash/get';
import { Spin, Tabs } from 'antd';
import { FormattedMessage } from 'react-intl';

import PkgTable from './PkgTable';
import TestTable from './TestTable';
Expand Down Expand Up @@ -103,20 +102,20 @@ export default class OneBuildTabs extends React.Component {
style={{ height: 'auto' }}
onChange={this.onTabChange}
>
<TabPane tab={<FormattedMessage id="buildinfo.pkgTab" />} key="pkginfo">
<TabPane tab={__i18n('包信息')} key="pkginfo">
<PkgTable
fetchOneBuild={this.props.fetchOneBuild}
data={getPkgInfo.packages}
platform={getPkgInfo.platform}
/>
</TabPane>
<TabPane tab={<FormattedMessage id="buildinfo.testTab" />} key="test">
<TabPane tab={__i18n('测试结果')} key="test">
<TestTable data={this.getTestInfo()} />
</TabPane>
<TabPane tab={<FormattedMessage id="buildinfo.extraTab" />} key="extrainfo">
<TabPane tab={__i18n('扩展信息')} key="extrainfo">
<ExtraTable data={this.getExtraInfo()} />
</TabPane>
<TabPane tab={<FormattedMessage id="buildinfo.filesTab" />} key="fileinfo">
<TabPane tab={__i18n('产物')} key="fileinfo">
<FileTable data={this.getFileInfo()} />
</TabPane>
</Tabs>
Expand Down
13 changes: 6 additions & 7 deletions view/src/components/PkgTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import QRCode from 'qrcode-react';
import { FormattedMessage } from 'react-intl';

import {
Table,
Expand Down Expand Up @@ -32,16 +31,16 @@ export default class PkgTable extends React.Component {

getColumns = () => {
let columns = [{
title: <FormattedMessage id="buildinfo.pkg.version" />,
title: __i18n('版本号'),
dataIndex: 'version',
width: 100,
}, {
title: <FormattedMessage id="buildinfo.pkg.type" />,
title: __i18n('类型'),
dataIndex: 'type',
width: 160,
}];
columns = columns.concat([{
title: <FormattedMessage id="buildinfo.pkg.download" />,
title: __i18n('下载'),
dataIndex: 'download',
width: 160,
render: (value, record) => {
Expand All @@ -52,14 +51,14 @@ export default class PkgTable extends React.Component {
onClick={this.showQrCodeModal.bind(this, record)}
/>
<a href={value} style={{ marginLeft: '8px' }} target="_blank">
<FormattedMessage id="buildinfo.pkg.download" />
{__i18n('下载')}
</a>
</span>
);
},
}]);
columns = columns.concat([{
title: <FormattedMessage id="buildinfo.pkg.gitBranch" />,
title: __i18n('代码分支'),
dataIndex: 'gitBranch',
width: 300,
render: (value, record) => {
Expand All @@ -68,7 +67,7 @@ export default class PkgTable extends React.Component {
);
},
}, {
title: <FormattedMessage id="buildinfo.pkg.gitInfo" />,
title: __i18n('提交信息'),
width: 240,
dataIndex: 'gitCommit',
render: (value, record) => {
Expand Down
7 changes: 3 additions & 4 deletions view/src/components/SiderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
LineChartOutlined,
SettingOutlined,
} from '@ant-design/icons';
import { FormattedMessage } from 'react-intl';

const { Sider } = Layout;

Expand Down Expand Up @@ -46,15 +45,15 @@ export default class SiderBar extends React.Component {
<Link to="/">
<FlagOutlined />
<span>
<FormattedMessage id="sidebar.buildinfo" />
{__i18n('构建信息')}
</span>
</Link>
</Menu.Item>
<Menu.Item key="/insight">
<Link to="/insight">
<span>
<LineChartOutlined />
<FormattedMessage id="sidebar.insight" />
{__i18n('洞察')}
</span>
</Link>
</Menu.Item>
Expand All @@ -63,7 +62,7 @@ export default class SiderBar extends React.Component {
<Link to="/setting">
<SettingOutlined />
<span>
<FormattedMessage id="sidebar.setting" />
{__i18n('设置')}
</span>
</Link>
</Menu.Item>
Expand Down
4 changes: 2 additions & 2 deletions view/src/components/SiteSetting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import safeGet from 'lodash/get';
import { FormattedMessage } from 'react-intl';

import {
Form,
Spin,
Expand Down Expand Up @@ -83,7 +83,7 @@ function SiteSetting() {
htmlType="submit"
onClick={updateSite}
>
<FormattedMessage id="setting.submit" />
{__i18n('更新设置')}
</Button>
</Form.Item>
</Spin>
Expand Down
Loading

0 comments on commit 3d6f80e

Please sign in to comment.