Commit 303206ac authored by Oleksii Savran's avatar Oleksii Savran Committed by Viacheslav Pavlov
Browse files

Resolve "Language navigation"

parent b7a47947
......@@ -9,6 +9,7 @@ import { createStore, applyMiddleware } from 'redux';
import { I18nextProvider } from 'react-i18next';
import thunk from 'redux-thunk';
import rootReducer from 'reducers';
import languages from 'data/Languages';
// import { create as createJss } from 'jss';
// import jssPreset from 'jss-preset-default';
......@@ -90,7 +91,15 @@ const prerenderer = (html, errHtml) => (req, res) => {
console.log('initialState:', initialState);
}
return html.replace(/SERVER_RENDERED_(CSS|STATE|HTML|TITLE|I18NSTORE|DIR|LANG)/g, (match, x) => {
const languageLinks = languages.map((lang) => {
if (lang.short === 'en') {
return `<link rel="alternate" hreflang="${lang.short}" href="${req.protocol + '://' + req.get('host')}${req.url}" />`;
} else {
return `<link rel="alternate" hreflang="${lang.short}" href="${req.protocol + '://' + req.get('host')}/${lang.short}${req.url}" />`;
}
});
return html.replace(/SERVER_RENDERED_(CSS|STATE|HTML|TITLE|I18NSTORE|DIR|LANG|HEADLINKS)/g, (match, x) => {
console.log(`Injecting ${match}`);
switch (match) {
case 'SERVER_RENDERED_CSS': return sheets.toString();
......@@ -100,6 +109,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
case 'SERVER_RENDERED_I18NSTORE': return serialize(initialI18nStore, {isJSON: true});
case 'SERVER_RENDERED_DIR': return serialize(getDir(initialLanguage), {isJSON: false});
case 'SERVER_RENDERED_LANG': return serialize(initialLanguage, {isJSON: false});
case 'SERVER_RENDERED_HEADLINKS': return languageLinks.join('');
default: console.log(`Unrecognized variable in ssr-template.html: ${match}`); return '';
}
});
......
......@@ -3,6 +3,7 @@
<head>
<title>SERVER_RENDERED_TITLE</title>
SERVER_RENDERED_HEADLINKS
<base href="FRONTEND_PATH" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes" />
......
......@@ -94,7 +94,8 @@ class LanguageList extends React.Component<ILanguageListProps, any> {
}
public render() {
const { classes, i18n, color } = this.props;
const { classes, i18n, color, location } = this.props;
console.log(location);
let currentLang = i18n.language;
languages.some((item, i, arr) => {
if (item.short === i18n.language) {
......@@ -129,7 +130,7 @@ class LanguageList extends React.Component<ILanguageListProps, any> {
{
// Using <a href="ru/" will reload app from server
languages.map((lang, index) => (
<a key={ (lang.short) } href={ `${lang.short === 'en' ? '' : lang.short}/` }><MenuItem>{ `${lang.label}` }</MenuItem></a>
<a key={ (lang.short) } href={ `${lang.short === 'en' ? '' : lang.short}${location.pathname}` }><MenuItem>{ `${lang.label}` }</MenuItem></a>
))
}
</Menu>
......
......@@ -240,7 +240,7 @@ class AdminHeader extends React.Component<IHeaderProps | any, any> {
<div
className={ `float-right` }>{ this.renderLogin([ROLE_USER, ROLE_ADMINISTRATOR]) }</div>
<div>
<LanguageList color={ menuTheme.langList }/>
<LanguageList location={ location } color={ menuTheme.langList }/>
</div>
</div>
</Toolbar>
......
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