mirror of
https://github.com/eyebluecn/tank-front
synced 2024-04-21 12:31:55 +00:00
Ready to refine the global i18n feature.
This commit is contained in:
+2
-5
@@ -1,19 +1,16 @@
|
||||
import React from 'react';
|
||||
import './App.less';
|
||||
import {Button} from "antd";
|
||||
import {BrowserRouter as Router} from "react-router-dom";
|
||||
import {ConfigProvider} from 'antd';
|
||||
import Frame from "./pages/Frame";
|
||||
import zhCN from 'antd/lib/locale-provider/zh_CN';
|
||||
|
||||
import en_US from 'antd/es/locale/en_US';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<ConfigProvider locale={en_US}>
|
||||
<Frame/>
|
||||
</ConfigProvider>
|
||||
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
import User from "../user/User";
|
||||
import Preference from "../preference/Preference";
|
||||
import BrowserUtil from "../../util/BrowserUtil";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export default class Moon {
|
||||
|
||||
@@ -24,6 +26,16 @@ export default class Moon {
|
||||
static getSingleton(): Moon {
|
||||
if (Moon.singleton == null) {
|
||||
Moon.singleton = new Moon();
|
||||
|
||||
//读取默认的语言
|
||||
let lang = BrowserUtil.browserLang()
|
||||
let localLang = Cookies.get("_lang");
|
||||
if (localLang === "zh" || localLang === "en") {
|
||||
lang = localLang
|
||||
}
|
||||
Moon.singleton.lang = lang
|
||||
console.log("当前浏览器默认语言是:", lang)
|
||||
|
||||
}
|
||||
|
||||
return Moon.singleton
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
* 这个类不包含Base的子类,比如User, Preference.
|
||||
* 和Moon形成姊妹篇
|
||||
*/
|
||||
import BrowserUtil from "../../util/BrowserUtil";
|
||||
import Cookies from "js-cookie"
|
||||
|
||||
export default class Sun {
|
||||
|
||||
//全局的一个store对象
|
||||
@@ -17,6 +20,8 @@ export default class Sun {
|
||||
//全局布局样式,是否展示出左边的菜单.
|
||||
showDrawer: boolean = true
|
||||
|
||||
|
||||
|
||||
//由于这个类采用单例模式,因此所有属性都是独一份的。
|
||||
constructor() {
|
||||
|
||||
@@ -26,6 +31,7 @@ export default class Sun {
|
||||
static getSingleton(): Sun {
|
||||
if (Sun.singleton == null) {
|
||||
Sun.singleton = new Sun();
|
||||
|
||||
}
|
||||
return Sun.singleton
|
||||
}
|
||||
|
||||
@@ -110,4 +110,19 @@ export default class BrowserUtil {
|
||||
return window.location.protocol + "//" + window.location.host
|
||||
}
|
||||
|
||||
|
||||
//只支持zh和en
|
||||
static browserLang() {
|
||||
//常规浏览器语言和IE浏览器
|
||||
let lang = navigator.language || (navigator as any).userLanguage;
|
||||
|
||||
//截取lang前2位字符
|
||||
lang = lang.substr(0, 2);
|
||||
if (lang === "zh") {
|
||||
return "zh"
|
||||
} else {
|
||||
return "en"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -19,9 +19,9 @@ import InstallIndex from './install/Index';
|
||||
import MatterList from './matter/List';
|
||||
import MatterDetail from './matter/Detail';
|
||||
|
||||
|
||||
import ShareList from './share/List';
|
||||
import ShareDetail from './share/Detail';
|
||||
import Index from './index/Index';
|
||||
import User from '../common/model/user/User';
|
||||
import Moon from '../common/model/global/Moon';
|
||||
import Sun from '../common/model/global/Sun';
|
||||
@@ -130,7 +130,6 @@ class RawFrame extends TankComponent<IProps, IState> {
|
||||
<Route exact path="/" render={() =>
|
||||
<Redirect to="/matter/list"/>
|
||||
}/>
|
||||
<Route path="/index" component={Index}/>
|
||||
<Route path="/user/login" component={UserLogin}/>
|
||||
<Route path="/user/detail/:uuid" component={UserDetail}/>
|
||||
<Route path="/user/list" component={UserList}/>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
.index-page {
|
||||
|
||||
padding: 20px;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import React from 'react';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import './Index.less';
|
||||
import TankComponent from '../../common/component/TankComponent';
|
||||
import Moon from '../../common/model/global/Moon';
|
||||
import User from '../../common/model/user/User';
|
||||
|
||||
interface IProps extends RouteComponentProps {
|
||||
|
||||
}
|
||||
|
||||
interface IState {
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default class Index extends TankComponent<IProps, IState> {
|
||||
|
||||
user: User = Moon.getSingleton().user;
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
let that = this;
|
||||
|
||||
that.updateUI();
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
|
||||
let that = this;
|
||||
|
||||
return (
|
||||
<div className="index-page">
|
||||
|
||||
<h1>欢迎来到蓝眼博客,这里是首页,内容正在开发中。</h1>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import TankComponent from "../../common/component/TankComponent";
|
||||
import Preference from "../../common/model/preference/Preference";
|
||||
import Moon from "../../common/model/global/Moon";
|
||||
import DefaultLogoPng from '../../assets/image/logo.png';
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
interface IProps {
|
||||
|
||||
@@ -26,6 +27,14 @@ export default class BottomLayout extends TankComponent <IProps, IState> {
|
||||
|
||||
changeLang() {
|
||||
|
||||
if (Moon.getSingleton().lang === 'zh') {
|
||||
Moon.getSingleton().lang = 'en'
|
||||
} else {
|
||||
Moon.getSingleton().lang = 'zh'
|
||||
}
|
||||
Cookies.set('_lang', Moon.getSingleton().lang);
|
||||
|
||||
this.updateUI()
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -43,7 +52,7 @@ export default class BottomLayout extends TankComponent <IProps, IState> {
|
||||
<span dangerouslySetInnerHTML={{__html: preference.record}}/>
|
||||
</span>
|
||||
<span className="item">
|
||||
<span onClick={this.changeLang.bind(this)}>
|
||||
<span className="link" onClick={this.changeLang.bind(this)}>
|
||||
{Moon.getSingleton().lang === 'zh' ? 'English' : '中文'}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
@@ -116,6 +116,8 @@ export default class Index extends TankComponent<IProps, IState> {
|
||||
https://tank-doc.eyeblue.cn/zh
|
||||
</a>
|
||||
</InfoCell>
|
||||
|
||||
|
||||
</TankContentCard>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user