Commit 2d5e2851 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Change language switch behavior

parent 1c348c55
......@@ -29,7 +29,7 @@
"regular_member": "Ordentliches Mitglied",
"extraordinary_member": "Ausserordentliches Mitglied",
"honorary_member": "Ehrenmitglied",
"frontpage.whats_hot": "What's HOT right now?",
"frontpage.whats_hot": "Was ist brandaktuell?",
"frontpage.social_media": "Folge uns auf Social Media",
"profile.free_beer": "Du bist berechtigt, gratis Bier zu beziehen!",
"profile.set_rfid": "Setze deine RFID unten, um gratis Bier zu erhalten!",
......
import m from 'mithril';
import i18n from 'i18n4v';
import german from '../languages/de.json';
import english from '../languages/en.json';
......@@ -38,10 +39,11 @@ function loadLanguage() {
function switchLanguage() {
if (_currentLanguage === 'en') {
changeLanguage('de');
_currentLanguage = 'de';
} else {
changeLanguage('en');
_currentLanguage = 'en';
}
m.route.set(`/${_currentLanguage}${m.route.get().substring(3)}`);
}
function currentLanguage() {
......
......@@ -5,26 +5,29 @@ import { currentLanguage } from './language';
const defaultTabs = ['AMIV', 'Events', 'Studienunterlagen', 'Jobs'];
const tabsLoggedOut = ['Login'];
const tabsLoggedIn = ['Profile', 'Logout'];
const tabToUrl = {
AMIV: { href: `/${currentLanguage()}/`, onupdate: m.route.link, index: 0 },
Events: { href: `/${currentLanguage()}/events`, onupdate: m.route.link, index: 1 },
Studienunterlagen: {
href: `/${currentLanguage()}/studydocuments`,
onupdate: m.route.link,
index: 2,
},
Jobs: { href: `/${currentLanguage()}/jobs`, onupdate: m.route.link, index: 3 },
Login: { href: `/${currentLanguage()}/login`, onupdate: m.route.link, index: 4 },
Profile: { href: `/${currentLanguage()}/profile`, onupdate: m.route.link, index: 4 },
Logout: { href: `/${currentLanguage()}/logout`, onupdate: m.route.link, index: 5 },
};
function tabToUrl() {
return {
AMIV: { href: `/${currentLanguage()}/`, onupdate: m.route.link, index: 0 },
Events: { href: `/${currentLanguage()}/events`, onupdate: m.route.link, index: 1 },
Studienunterlagen: {
href: `/${currentLanguage()}/studydocuments`,
onupdate: m.route.link,
index: 2,
},
Jobs: { href: `/${currentLanguage()}/jobs`, onupdate: m.route.link, index: 3 },
Login: { href: `/${currentLanguage()}/login`, onupdate: m.route.link, index: 4 },
Profile: { href: `/${currentLanguage()}/profile`, onupdate: m.route.link, index: 4 },
Logout: { href: `/${currentLanguage()}/logout`, onupdate: m.route.link, index: 5 },
};
}
export default class Navigation {
constructor() {
checkLogin();
this._wasLoggedIn = isLoggedIn();
this._selectedTabIndex = 0;
Object.values(tabToUrl)
Object.values(tabToUrl())
.filter(tab => m.route.get().includes(tab.href))
.forEach(tab => {
this._selectedTabIndex = tab.index;
......@@ -50,7 +53,7 @@ export default class Navigation {
this._tabs.forEach(tab => {
this._tabOptions.tabs.push({
label: tab,
url: tabToUrl[tab],
url: tabToUrl()[tab],
});
});
}
......@@ -60,7 +63,7 @@ export default class Navigation {
}
onupdate() {
Object.values(tabToUrl)
Object.values(tabToUrl())
.filter(tab => m.route.get().includes(tab.href))
.forEach(tab => {
this._selectedTabIndex = tab.index;
......
Supports Markdown
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