Extracted strings and fixes on localization support
Language chooser in the UI
This commit is contained in:
parent
9f449c0a2f
commit
dc7789c17b
126 changed files with 2919 additions and 2028 deletions
|
@ -3,62 +3,102 @@
|
|||
import './lib/public-path';
|
||||
|
||||
import React, {Component} from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {
|
||||
I18nextProvider,
|
||||
withNamespaces
|
||||
} from 'react-i18next';
|
||||
import i18n from './lib/i18n';
|
||||
import ReactDOM
|
||||
from 'react-dom';
|
||||
import {I18nextProvider} from 'react-i18next';
|
||||
import i18n, {withTranslation} from './lib/i18n';
|
||||
|
||||
import account from './account/root';
|
||||
import blacklist from './blacklist/root';
|
||||
import lists from './lists/root';
|
||||
import namespaces from './namespaces/root';
|
||||
import reports from './reports/root';
|
||||
import campaigns from './campaigns/root';
|
||||
import templates from './templates/root';
|
||||
import users from './users/root';
|
||||
import sendConfigurations from './send-configurations/root';
|
||||
import settings from './settings/root';
|
||||
import account
|
||||
from './account/root';
|
||||
import blacklist
|
||||
from './blacklist/root';
|
||||
import lists
|
||||
from './lists/root';
|
||||
import namespaces
|
||||
from './namespaces/root';
|
||||
import reports
|
||||
from './reports/root';
|
||||
import campaigns
|
||||
from './campaigns/root';
|
||||
import templates
|
||||
from './templates/root';
|
||||
import users
|
||||
from './users/root';
|
||||
import sendConfigurations
|
||||
from './send-configurations/root';
|
||||
import settings
|
||||
from './settings/root';
|
||||
|
||||
import {
|
||||
MenuLink,
|
||||
Section
|
||||
} from "./lib/page";
|
||||
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
import Home from "./Home";
|
||||
import mailtrainConfig
|
||||
from 'mailtrainConfig';
|
||||
import Home
|
||||
from "./Home";
|
||||
import {
|
||||
ActionLink,
|
||||
DropdownMenuItem,
|
||||
Icon
|
||||
} from "./lib/bootstrap-components";
|
||||
import {Link} from "react-router-dom";
|
||||
import axios from './lib/axios';
|
||||
import axios
|
||||
from './lib/axios';
|
||||
import {getUrl} from "./lib/urls";
|
||||
import {langCodes} from "../../shared/langs";
|
||||
|
||||
const topLevelMenuKeys = ['lists', 'templates', 'campaigns', 'reports'];
|
||||
|
||||
@withNamespaces()
|
||||
@withTranslation()
|
||||
class Root extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
const t = props.t;
|
||||
const self = this;
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
const topLevelMenuKeys = ['lists', 'templates', 'campaigns', 'reports'];
|
||||
const structure = {};
|
||||
|
||||
// The MainMenu component is defined here in order to avoid recreating menu structure on every change in the main menu
|
||||
// This is because Root component depends only on the language, thus it is redrawn (and the structure is recomputed) only when the language changes
|
||||
class MainMenu extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await axios.post(getUrl('rest/logout'));
|
||||
window.location = getUrl();
|
||||
}
|
||||
|
||||
render() {
|
||||
const languageOptions = [];
|
||||
for (const lng of mailtrainConfig.enabledLanguages) {
|
||||
const langDesc = langCodes[lng];
|
||||
const label = langDesc.getLabel(t);
|
||||
|
||||
languageOptions.push(
|
||||
<li key={lng}><ActionLink onClickAsync={() => i18n.changeLanguage(langDesc.shortCode)}>{label}</ActionLink></li>
|
||||
)
|
||||
}
|
||||
|
||||
const currentLngCode = langCodes[i18n.language].getShortLabel(t);
|
||||
|
||||
const path = this.props.location.pathname;
|
||||
|
||||
const topLevelItems = structure[""].children;
|
||||
|
||||
const topLevelMenu = [];
|
||||
const topLevelItems = self.structure[''].children;
|
||||
|
||||
for (const entryKey of topLevelMenuKeys) {
|
||||
const entry = topLevelItems[entryKey];
|
||||
const link = entry.link || entry.externalLink;
|
||||
|
||||
if (link && path.startsWith(link)) {
|
||||
topLevelMenu.push(<MenuLink key={entryKey} className="active" to={link}>{entry.title} <span className="sr-only">{t('root.current')}</span></MenuLink>);
|
||||
topLevelMenu.push(<MenuLink key={entryKey} className="active" to={link}>{entry.title} <span className="sr-only">{t('current')}</span></MenuLink>);
|
||||
} else {
|
||||
topLevelMenu.push(<MenuLink key={entryKey} to={link}>{entry.title}</MenuLink>);
|
||||
}
|
||||
|
@ -69,7 +109,7 @@ class Root extends Component {
|
|||
<div className="container-fluid">
|
||||
<div className="navbar-header">
|
||||
<button type="button" className="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
|
||||
<span className="sr-only">{t('root.toggleNavigation')}</span>
|
||||
<span className="sr-only">{t('toggleNavigation')}</span>
|
||||
<span className="icon-bar"></span>
|
||||
<span className="icon-bar"></span>
|
||||
<span className="icon-bar"></span>
|
||||
|
@ -77,30 +117,41 @@ class Root extends Component {
|
|||
<Link className="navbar-brand" to="/"><Icon icon="envelope"/> Mailtrain</Link>
|
||||
</div>
|
||||
|
||||
{mailtrainConfig.isAuthenticated &&
|
||||
<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||
<ul className="nav navbar-nav">
|
||||
{topLevelMenu}
|
||||
<DropdownMenuItem label={t('root.administration')}>
|
||||
<MenuLink to="/users"><Icon icon='cog'/> {t('user_plural')}</MenuLink>
|
||||
<MenuLink to="/namespaces"><Icon icon='cog'/> {t('namespace_plural')}</MenuLink>
|
||||
{mailtrainConfig.globalPermissions.manageSettings && <MenuLink to="/settings"><Icon icon='cog'/> {t('globalSetting_plural')}</MenuLink>}
|
||||
<MenuLink to="/send-configurations"><Icon icon='cog'/> {t('sendConfiguration_plural')}</MenuLink>
|
||||
{mailtrainConfig.globalPermissions.manageBlacklist && <MenuLink to="/blacklist"><Icon icon='ban-circle'/> {t('blacklist')}</MenuLink>}
|
||||
<MenuLink to="/account/api"><Icon icon='retweet'/> {t('api')}</MenuLink>
|
||||
</DropdownMenuItem>
|
||||
</ul>
|
||||
{mailtrainConfig.isAuthenticated ?
|
||||
<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||
<ul className="nav navbar-nav">
|
||||
{topLevelMenu}
|
||||
<DropdownMenuItem label={t('administration')}>
|
||||
<MenuLink to="/users"><Icon icon='cog'/> {t('users')}</MenuLink>
|
||||
<MenuLink to="/namespaces"><Icon icon='cog'/> {t('namespaces')}</MenuLink>
|
||||
{mailtrainConfig.globalPermissions.manageSettings && <MenuLink to="/settings"><Icon icon='cog'/> {t('globalSettings')}</MenuLink>}
|
||||
<MenuLink to="/send-configurations"><Icon icon='cog'/> {t('sendConfigurations')}</MenuLink>
|
||||
{mailtrainConfig.globalPermissions.manageBlacklist && <MenuLink to="/blacklist"><Icon icon='ban-circle'/> {t('blacklist')}</MenuLink>}
|
||||
<MenuLink to="/account/api"><Icon icon='retweet'/> {t('api')}</MenuLink>
|
||||
</DropdownMenuItem>
|
||||
</ul>
|
||||
|
||||
|
||||
<ul className="nav navbar-nav navbar-right">
|
||||
<DropdownMenuItem label={mailtrainConfig.user.username} icon="user">
|
||||
<MenuLink to="/account"><Icon icon='user'/> {t('root.account')}</MenuLink>
|
||||
<li>
|
||||
<ActionLink onClickAsync={::self.logout}><Icon icon='log-out'/> {t('logout')}</ActionLink>
|
||||
</li>
|
||||
</DropdownMenuItem>
|
||||
</ul>
|
||||
</div>
|
||||
<ul className="nav navbar-nav navbar-right">
|
||||
<DropdownMenuItem label={currentLngCode}>
|
||||
{languageOptions}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem label={mailtrainConfig.user.username} icon="user">
|
||||
<MenuLink to="/account"><Icon icon='user'/> {t('account')}</MenuLink>
|
||||
<li>
|
||||
<ActionLink onClickAsync={::this.logout}><Icon icon='log-out'/> {t('logOut')}</ActionLink>
|
||||
</li>
|
||||
</DropdownMenuItem>
|
||||
</ul>
|
||||
</div>
|
||||
:
|
||||
<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||
<ul className="nav navbar-nav navbar-right">
|
||||
<DropdownMenuItem label={currentLngCode}>
|
||||
{languageOptions}
|
||||
</DropdownMenuItem>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
@ -109,43 +160,32 @@ class Root extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
this.structure = {
|
||||
'': {
|
||||
title: t('Home'),
|
||||
structure[''] ={
|
||||
title: t('home'),
|
||||
link: '/',
|
||||
panelComponent: Home,
|
||||
primaryMenuComponent: MainMenu,
|
||||
children: {
|
||||
...lists.getMenus(t),
|
||||
...reports.getMenus(t),
|
||||
...templates.getMenus(t),
|
||||
...namespaces.getMenus(t),
|
||||
...users.getMenus(t),
|
||||
...blacklist.getMenus(t),
|
||||
...account.getMenus(t),
|
||||
...settings.getMenus(t),
|
||||
...sendConfigurations.getMenus(t),
|
||||
...campaigns.getMenus(t)
|
||||
}
|
||||
...lists.getMenus(t),
|
||||
...reports.getMenus(t),
|
||||
...templates.getMenus(t),
|
||||
...namespaces.getMenus(t),
|
||||
...users.getMenus(t),
|
||||
...blacklist.getMenus(t),
|
||||
...account.getMenus(t),
|
||||
...settings.getMenus(t),
|
||||
...sendConfigurations.getMenus(t),
|
||||
...campaigns.getMenus(t)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await axios.post(getUrl('rest/logout'));
|
||||
window.location = getUrl();
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Section root='/' structure={this.structure}/>
|
||||
<Section root='/' structure={structure}/>
|
||||
|
||||
<footer className="footer">
|
||||
<div className="container-fluid">
|
||||
<p className="text-muted">© 2018 <a href="https://mailtrain.org">Mailtrain.org</a>, <a href="mailto:info@mailtrain.org">info@mailtrain.org</a>. <a href="https://github.com/Mailtrain-org/mailtrain">{t('sourceOnGithub')}</a></p>
|
||||
<p className="text-muted">© 2018 <a href="https://mailtrain.org">Mailtrain.org</a>, <a href="mailto:info@mailtrain.org">info@mailtrain.org</a>. <a href="https://github.com/Mailtrain-org/mailtrain">{t('sourceOnGitHub')}</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue