Commit d50eead4 authored by Curtis Adam's avatar Curtis Adam
Browse files

Refactor i18n and cookie consent initialization

parent 91cb296c
// STARTUP IMPORTS
import "../imports/startup/client/i18n.js";
import "../imports/config/accounts.js";
import "../imports/ui/main/main.js";
import "../imports/startup/client/routes/main.js";
import "../imports/startup/client/registerhelper/main.js";
import "../imports/startup/client/registerServiceWorker";
import {Session} from "meteor/session";
import {ServerStyle} from "../imports/util/styles.js";
window.addEventListener("load", function () {
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#4A5C66",
"text": "#ffffff"
},
"button": {
"background": "lightgrey",
"text": "#4a5c66"
}
},
"theme": "edgeless",
"position": "bottom-right",
"content": {
"message": TAPi18n.__('cookieconsent.message', {firstAppTitle: ServerStyle.getFirstAppTitle(), lastAppTitle: ServerStyle.getLastAppTitle()}, (Session.get('activeLanguage'))),
"dismiss": TAPi18n.__('cookieconsent.dismiss', {}, (Session.get('activeLanguage'))),
"link": TAPi18n.__('cookieconsent.link', {}, (Session.get('activeLanguage'))),
"href": "/datenschutz"
}
});
});
// USER INTERFACE IMPORTS -------------------------------------------------
import {Session} from "meteor/session";
import {Meteor} from "meteor/meteor";
//------------------------ GET LANGUAGE FROM USER
export function getUserLanguage() {
Session.set('activeLanguage', "de");
return Session.get('activeLanguage');
}
//------------------------ LOADING I18N
Meteor.startup(function () {
Meteor.absoluteUrl.defaultOptions.rootUrl = Meteor.settings.public.rooturl;
TAPi18n.setLanguage(getUserLanguage());
});
<template name="main">
<div id="pomodoroTimerOverlay">
<div class="svg-container">
{{#if isLeitnerWozniakRoute}}
{{> pomodoroTimer}}
{{/if}}
{{#if loadedTranslation}}
<div id="pomodoroTimerOverlay">
<div class="svg-container">
{{#if isLeitnerWozniakRoute}}
{{> pomodoroTimer}}
{{/if}}
</div>
</div>
</div>
{{checkIfUserIsSelectingACardset}}
{{> mainModalConnectionStatus}}
{{> mainModalUnderDevelopment}}
{{> mainItemSearchResult}}
{{#if displayMainNavigation}}
{{> mainNavigationTop}}
{{checkIfUserIsSelectingACardset}}
{{> mainModalConnectionStatus}}
{{> mainModalUnderDevelopment}}
{{> mainItemSearchResult}}
{{#if displayMainNavigation}}
{{> mainNavigationTop}}
{{/if}}
{{> messageOfTheDayModal}}
{{> messagePreviewModal}}
{{> useCasesModal}}
{{> impressumModalStatistics}}
{{> learningStatusModal}}
{{> mainPdfViewerModal}}
<div id="main" class="{{getMainContainer}}">
{{> yield}}
</div>
{{> mainNavigationFooter}}
{{else}}
{{> loadingScreen}}
{{/if}}
{{> messageOfTheDayModal}}
{{> messagePreviewModal}}
{{> useCasesModal}}
{{> impressumModalStatistics}}
{{> learningStatusModal}}
{{> mainPdfViewerModal}}
<div id="main" class="{{getMainContainer}}">
{{> yield}}
</div>
{{> mainNavigationFooter}}
</template>
......@@ -41,6 +41,7 @@ import 'tippy.js/animations/scale-extreme.css';
import {BackgroundChanger} from "../../util/backgroundChanger";
import {LockScreen} from "../../util/lockScreen";
import {SweetAlertMessages} from "../../util/sweetAlert";
import {Utilities} from "../../util/utilities";
Meteor.subscribe("notifications");
Meteor.subscribe("serverStatistics");
......@@ -91,6 +92,9 @@ Session.setDefault('errorReportingCard', undefined);
Session.setDefault('errorReportingMode', false);
Session.setDefault('showOnlyErrorReports', false);
//Language Sessions
Session.setDefault('loadedTranslation', false);
function connectionStatus() {
let stat;
if (Meteor.status().status === "connected") {
......@@ -128,6 +132,9 @@ Template.main.events({
});
Template.main.helpers({
loadedTranslation: function () {
return Session.get('loadedTranslation');
},
checkIfUserIsSelectingACardset: function () {
if (!Route.isCardset() && !Route.isRepetitorium() && !Route.isPool()) {
Session.set('selectingCardsetToLearn', false);
......@@ -222,6 +229,9 @@ Template.main.onDestroyed(function () {
});
Meteor.startup(function () {
Session.set('loadedTranslation', false);
Meteor.absoluteUrl.defaultOptions.rootUrl = Meteor.settings.public.rooturl;
CardNavigation.fullscreenExitEvents();
$(document).on('keydown', function (event) {
MainNavigation.keyEvents(event);
......@@ -231,6 +241,8 @@ Meteor.startup(function () {
MainNavigation.enableKeyEvents();
CardNavigation.enableKeyEvents();
});
Utilities.setActiveLanguage();
});
document.addEventListener('fullscreenerror', () => {
......
......@@ -5,7 +5,6 @@ import {Template} from "meteor/templating";
import {Session} from "meteor/session";
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
import {Route} from "../../util/route.js";
import {getUserLanguage} from "../../startup/client/i18n";
import ResizeSensor from "../../../client/thirdParty/resizeSensor/ResizeSensor";
import {PomodoroTimer} from "../../util/pomodoroTimer";
import {NavigatorCheck} from "../../util/navigatorCheck";
......@@ -20,16 +19,11 @@ import "../messageOfTheDay/messageOfTheDay.js";
import "./welcome.html";
import {setLoginTarget} from "../../startup/client/routes/onBeforeAction.js";
import {Fullscreen} from "../../util/fullscreen";
import {Utilities} from "../../util/utilities";
Meteor.subscribe("pomodoroLandingPage");
Meteor.subscribe("userData");
function setActiveLanguage() {
let language = getUserLanguage();
TAPi18n.setLanguage(language);
Session.set('activeLanguage', language);
}
//------------------------ LOGIN EVENT
Template.welcome.events({
......@@ -40,7 +34,7 @@ Template.welcome.events({
throw new Meteor.Error("Facebook login failed");
} else {
Fullscreen.resetChooseModeSessions();
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......@@ -54,7 +48,7 @@ Template.welcome.events({
throw new Meteor.Error("Twitter login failed");
} else {
Fullscreen.resetChooseModeSessions();
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......@@ -68,7 +62,7 @@ Template.welcome.events({
throw new Meteor.Error("Google login failed");
} else {
Fullscreen.resetChooseModeSessions();
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......@@ -82,7 +76,7 @@ Template.welcome.events({
throw new Meteor.Error("CAS login failed");
} else {
Fullscreen.resetChooseModeSessions();
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......@@ -95,7 +89,7 @@ Template.welcome.events({
Meteor.insecureUserLogin($("#TestingBackdoorUsername").val(), function (err, result) {
if (result) {
Fullscreen.resetChooseModeSessions();
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......@@ -105,7 +99,7 @@ Template.welcome.events({
'click #guest': function () {
Fullscreen.resetChooseModeSessions();
MainNavigation.setGuestLogin("true");
setActiveLanguage();
Utilities.setActiveLanguage();
setLoginTarget();
}
});
......
......@@ -286,4 +286,37 @@ export let Utilities = class Utilities {
return _.sortBy(array, content).reverse();
}
}
static setActiveLanguage () {
Session.set('activeLanguage', "de");
TAPi18n.setLanguage(Session.get('activeLanguage')).done(function () {
console.log("trigger");
Session.set('loadedTranslation', true);
Utilities.triggerCookieConsent();
});
}
static triggerCookieConsent () {
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#4A5C66",
"text": "#ffffff"
},
"button": {
"background": "lightgrey",
"text": "#4a5c66"
}
},
"theme": "edgeless",
"position": "bottom-right",
"content": {
"message": TAPi18n.__('cookieconsent.message', {firstAppTitle: ServerStyle.getFirstAppTitle(), lastAppTitle: ServerStyle.getLastAppTitle()}, (Session.get('activeLanguage'))),
"dismiss": TAPi18n.__('cookieconsent.dismiss', {}, (Session.get('activeLanguage'))),
"link": TAPi18n.__('cookieconsent.link', {}, (Session.get('activeLanguage'))),
"href": "/datenschutz"
}
});
}
};
{
"helper_name": "_",
"supported_languages": null,
"i18n_files_route": "/tap-i18n",
"cdn_path": null,
"preloaded_langs": ["de", "en"]
}
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