fix locale 404 not default

This commit is contained in:
Jay 2017-04-05 15:35:32 +08:00
parent b684672ad2
commit 34f2d0e24a
3 changed files with 13 additions and 7 deletions

4
app.js
View File

@ -34,6 +34,10 @@ app.use(express.static(path.resolve(__dirname, 'public')));
app.use('/semantic', express.static(path.resolve(__dirname, 'node_modules', 'semantic-ui-css'))); app.use('/semantic', express.static(path.resolve(__dirname, 'node_modules', 'semantic-ui-css')));
app.use('/react-datetime', express.static(path.resolve(__dirname, 'node_modules', 'react-datetime', 'css'))); app.use('/react-datetime', express.static(path.resolve(__dirname, 'node_modules', 'react-datetime', 'css')));
app.use(/\/locales\/(\w+).json/, (req, res, n) => {
res.sendFile(path.resolve(__dirname, 'public', 'locales', 'zh.json'));
})
const server = app.listen(app.get('port'), () => { const server = app.listen(app.get('port'), () => {
console.log(`Server start on port ${server.address().port}`); console.log(`Server start on port ${server.address().port}`);
}); });

View File

@ -62215,7 +62215,8 @@ var Root = function (_React$Component) {
value: function componentDidMount() { value: function componentDidMount() {
var _this2 = this; var _this2 = this;
var lang = navigator.language.substring(0, 2); var slang = sessionStorage.getItem('lang');
var lang = slang || navigator.language.substring(0, 2);
fetch('/locales/' + lang + '.json').then(function (response) { fetch('/locales/' + lang + '.json').then(function (response) {
if (response.status == 200) return response.json(); if (response.status == 200) return response.json();
return {}; return {};

View File

@ -59,7 +59,8 @@ class Root extends React.Component {
} }
componentDidMount() { componentDidMount() {
let lang = navigator let slang = sessionStorage.getItem('lang');
let lang = slang || navigator
.language .language
.substring(0, 2); .substring(0, 2);
fetch(`/locales/${lang}.json`).then(response => { fetch(`/locales/${lang}.json`).then(response => {