diff --git a/console/src/main/resources/static/console-fe/src/constants.js b/console/src/main/resources/static/console-fe/src/constants.js index 0fa45b7d9..431d39bc1 100644 --- a/console/src/main/resources/static/console-fe/src/constants.js +++ b/console/src/main/resources/static/console-fe/src/constants.js @@ -11,7 +11,7 @@ * limitations under the License. */ -export const LANGUAGE_KEY = 'site_language'; +export const LANGUAGE_KEY = 'docsite_language'; export const LANGUAGE_SWITCH = 'LANGUAGE_SWITCH'; // TODO: 后端暂时没有统一成功失败标记 diff --git a/console/src/main/resources/static/console-fe/src/index.js b/console/src/main/resources/static/console-fe/src/index.js index b3d9f45bb..8aa65a736 100644 --- a/console/src/main/resources/static/console-fe/src/index.js +++ b/console/src/main/resources/static/console-fe/src/index.js @@ -50,7 +50,7 @@ import './index.scss'; module.hot && module.hot.accept(); if (!CookieHelp.getValue(LANGUAGE_KEY)) { - CookieHelp.setValue(LANGUAGE_KEY, navigator.language === 'zh-CN' ? 'zh-CN' : 'en-US'); + CookieHelp.setValue(LANGUAGE_KEY, navigator.language === 'zh-CN' ? 'zh-cn' : 'en-us'); } const reducer = combineReducers({ diff --git a/console/src/main/resources/static/console-fe/src/layouts/Header.js b/console/src/main/resources/static/console-fe/src/layouts/Header.js index 0524f12da..d3ee6ebec 100644 --- a/console/src/main/resources/static/console-fe/src/layouts/Header.js +++ b/console/src/main/resources/static/console-fe/src/layouts/Header.js @@ -15,7 +15,8 @@ import React from 'react'; import { connect } from 'react-redux'; import { ConfigProvider } from '@alifd/next'; import siteConfig from '../config'; -import { changeLanguage } from '../reducers/locale'; +import { changeLanguage } from '@/reducers/locale'; +import { aliwareIntl } from '@/globalLib'; import './index.scss'; @@ -28,14 +29,19 @@ class Header extends React.Component { static displayName = 'Header'; switchLang = () => { - const { language = 'en-US', changeLanguage } = this.props; - changeLanguage(language === 'en-US' ? 'zh-CN' : 'en-US'); + const { language = 'en-us', changeLanguage } = this.props; + const currentLanguage = language === 'en-us' ? 'zh-cn' : 'en-us'; + changeLanguage(currentLanguage); + aliwareIntl.changeLanguage(currentLanguage); + document.cookie = `docsite_language=${currentLanguage}`; + console.log(currentLanguage); + // window.location.reload(); }; render() { - const { locale = {}, language = 'en-US' } = this.props; + const { locale = {}, language = 'en-us' } = this.props; const { home, docs, blog, community, languageSwitchButton } = locale; - const BASE_URL = `https://nacos.io/${language.toLocaleLowerCase()}/`; + const BASE_URL = `https://nacos.io/${language}/`; const NAV_MENU = [ { id: 1, diff --git a/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js b/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js index a86e78667..6fa87645f 100644 --- a/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js +++ b/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js @@ -361,10 +361,12 @@ class MainLayout extends React.Component { }); } - componentDidMount() { - const nav = this.props.navList || []; - const navRow = this.nacosGetNav(nav); - this.setState({ navRow }, () => this.renderNav()); + componentWillReceiveProps() { + setTimeout(() => { + const nav = this.props.navList || []; + const navRow = this.nacosGetNav(nav); + this.setState({ navRow }, () => this.renderNav()); + }); } render() { diff --git a/console/src/main/resources/static/console-fe/src/reducers/locale.js b/console/src/main/resources/static/console-fe/src/reducers/locale.js index 287f0f736..b075999b7 100644 --- a/console/src/main/resources/static/console-fe/src/reducers/locale.js +++ b/console/src/main/resources/static/console-fe/src/reducers/locale.js @@ -21,14 +21,14 @@ const enUS = Object.assign({}, fusionEnUS, I18N.enUS); const zhCN = Object.assign({}, fusionZhCN, I18N.zhCN); const initialState = { - language: 'en-US', + language: 'en-us', locale: enUS, }; const changeLanguage = lang => dispatch => { - const language = lang === 'zh-CN' ? 'zh-CN' : 'en-US'; + const language = lang === 'zh-cn' ? 'zh-cn' : 'en-us'; CookieHelp.setValue(LANGUAGE_KEY, language); - dispatch({ type: LANGUAGE_SWITCH, language, locale: language === 'zh-CN' ? zhCN : enUS }); + dispatch({ type: LANGUAGE_SWITCH, language, locale: language === 'zh-cn' ? zhCN : enUS }); }; export default (state = initialState, action) => {