site: fix language detect function

This commit is contained in:
Benjy Cui 2016-09-10 11:19:03 +08:00
parent c79826ea83
commit 9ac4e6ea44
2 changed files with 7 additions and 6 deletions

View File

@ -3,10 +3,10 @@ import Promise from 'bluebird';
import MainContent from './MainContent';
// locale copy from layout
const locale = (
window.localStorage &&
localStorage.getItem('locale') !== 'en-US'
) ? 'zh-CN' : 'en-US';
const language = (typeof localStorage === 'undefined' || !localStorage.getItem('locale')) ?
navigator.language : localStorage.getItem('locale');
const isZhCN = language === 'zh-CN';
const locale = isZhCN ? 'zh-CN' : 'en-US';
export function collect(nextProps, callback) {
const pageData = nextProps.location.pathname === 'changelog' ?

View File

@ -12,8 +12,9 @@ window.react = React;
window['react-dom'] = ReactDOM;
window.antd = require('antd');
const isZhCN = (typeof localStorage !== 'undefined' && localStorage.getItem('locale') === 'zh-CN') ||
(navigator.language === 'zh-CN');
const language = (typeof localStorage === 'undefined' || !localStorage.getItem('locale')) ?
navigator.language : localStorage.getItem('locale');
const isZhCN = language === 'zh-CN';
const appLocale = isZhCN ? cnLocale : enLocale;
addLocaleData(appLocale.data);