Commit 8e8fb944 authored by 2breakegg's avatar 2breakegg

change language

parent bcd4546f
...@@ -13,6 +13,11 @@ export default { ...@@ -13,6 +13,11 @@ export default {
...state, ...action.payload, ...state, ...action.payload,
}; };
}, },
changeLanguage(state, { payload: id }) {
localStorage.setItem('locale', id.id);
history.go(0);
return state;
},
}, },
effects: {}, effects: {},
subscriptions: { subscriptions: {
......
import { Layout, Menu } from 'antd'; import { Layout, Menu, Dropdown, Icon } from 'antd';
import { connect } from 'dva'; import { connect } from 'dva';
import { Link } from 'dva/router'; import { Link } from 'dva/router';
import React from 'react'; import React from 'react';
...@@ -123,6 +123,21 @@ const particleConfig = { ...@@ -123,6 +123,21 @@ const particleConfig = {
}; };
function Index({ children, messages, dispatch }) { function Index({ children, messages, dispatch }) {
const language = localStorage.getItem('locale') || navigator.language || (navigator.languages && navigator.languages[0]) || navigator.userLanguage || navigator.browserLanguage || 'zh-CN' ;
const menu = (
<Menu style={{ transform: 'translateX(-16px)' }}>
<Menu.Item key="0">
<a onClick={() => { dispatch({ type: 'common/changeLanguage', payload: { id: 'en-US' } })}} className='changelanguage'>
&nbsp;English</a>
</Menu.Item>
<Menu.Item key="1">
<a onClick={() => { dispatch({ type: 'common/changeLanguage', payload: { id: 'zh-EN' } })}} className='changelanguage'>
&nbsp;中文</a>
</Menu.Item>
</Menu>
);
return ( return (
<div style={{ height: '100%'}}> <div style={{ height: '100%'}}>
<DocumentTitle title={messages.title || 'Moe Cube'} /> <DocumentTitle title={messages.title || 'Moe Cube'} />
...@@ -155,9 +170,22 @@ function Index({ children, messages, dispatch }) { ...@@ -155,9 +170,22 @@ function Index({ children, messages, dispatch }) {
<div onClick={() => { dispatch({ type : 'auth/signOut' }) }}> <div onClick={() => { dispatch({ type : 'auth/signOut' }) }}>
<Format id="sign-out"/> <Format id="sign-out"/>
</div> </div>
</Menu.Item>):('') </Menu.Item>) : ('')
} }
<Menu.Item key="2">
<Dropdown overlay={menu} trigger={['click']}>
{language === 'en-US' ?
(<a className="ant-dropdown-link changelanguage" href="#">
&nbsp;English <Icon type="down" className="flag" />
</a>) : (<a className="ant-dropdown-link changelanguage" href="#">
&nbsp;中文 <Icon type="down" className="flag" />
</a>)}
</Dropdown>
</Menu.Item>
</Menu> </Menu>
</Header> </Header>
<Particles <Particles
......
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