Commit 5bf31a42 authored by 陈帅's avatar 陈帅

add change lang button

parent c035a5fc
const path = require('path');
export default {
entry: 'src/index.js',
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
},
},
externals: {
'@antv/data-set': 'DataSet',
bizcharts: 'BizCharts',
rollbar: 'rollbar',
},
alias: {
components: path.resolve(__dirname, 'src/components/'),
},
ignoreMomentLocale: true,
theme: './src/theme.js',
html: {
template: './src/index.ejs',
},
publicPath: '/',
hash: true,
lessLoaderOptions: {
javascriptEnabled: true,
},
disableDynamicImport: true,
cssLoaderOptions: {
modules: true,
getLocalIdent: (context, localIdentName, localName) => {
if (
context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less')
) {
return localName;
}
const antdProPath = context.resourcePath.match(/src(.*)/)[1].replace('.less', '');
const arr = antdProPath
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
},
},
};
import React, { PureComponent } from 'react';
import { FormattedMessage } from 'react-intl';
import { Spin, Tag, Menu, Icon, Dropdown, Avatar, Tooltip } from 'antd';
import { Spin, Tag, Menu, Icon, Dropdown, Avatar, Tooltip, Button } from 'antd';
import moment from 'moment';
import groupBy from 'lodash/groupBy';
import NoticeIcon from '../NoticeIcon';
......@@ -40,6 +40,16 @@ export default class GlobalHeaderRight extends PureComponent {
return groupBy(newNotices, 'type');
}
changLang = () => {
const locale = localStorage.getItem('locale');
if (!locale || locale === 'zh-CN') {
localStorage.setItem('locale', 'en-US');
} else {
localStorage.setItem('locale', 'zh-CN');
}
location.reload();
};
render() {
const {
currentUser,
......@@ -141,8 +151,11 @@ export default class GlobalHeaderRight extends PureComponent {
</span>
</Dropdown>
) : (
<Spin size="small" style={{ marginLeft: 8 }} />
<Spin size="small" style={{ marginLeft: 8, marginRight: 8 }} />
)}
<Button size="small" onClick={this.changLang}>
<FormattedMessage id="navbar.lang" />
</Button>
</div>
);
}
......
......@@ -7,6 +7,7 @@ export default {
data: appLocaleData,
antd: antdEn,
messages: {
'navbar.lang': 'English',
'menu.home': 'Home',
'menu.dashboard': 'Dashboard',
'menu.dashboard.analysis': 'Analysis',
......
......@@ -7,6 +7,7 @@ export default {
data: appLocaleData,
antd: antdZh,
messages: {
'navbar.lang': '中文',
'menu.home': '首页',
'menu.dashboard': 'Dashboard',
'menu.dashboard.analysis': '分析页',
......
......@@ -322,6 +322,7 @@ class Analysis extends Component {
<Col {...topColResponsiveProps}>
<ChartCard
bordered={false}
loading={loading}
title={<FormattedMessage id="app.analysis.visits" defaultMessage="visits" />}
action={
<Tooltip
......@@ -349,6 +350,7 @@ class Analysis extends Component {
<Col {...topColResponsiveProps}>
<ChartCard
bordered={false}
loading={loading}
title={<FormattedMessage id="app.analysis.payments" defaultMessage="Payments" />}
action={
<Tooltip
......
......@@ -18,11 +18,10 @@ dynamic.setDefaultLoadingComponent(() => {
});
function getLang() {
if (window) {
return 'en-US';
if (window.localStorage && localStorage.getItem('locale')) {
return localStorage.getItem('locale');
}
return (window.localStorage && localStorage.getItem('locale')) ||
(navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us'
return (navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us'
? 'en-US'
: 'zh-CN';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment