Skip to content

Commit

Permalink
initial trail with DE versiob
Browse files Browse the repository at this point in the history
  • Loading branch information
rschlaefli committed Sep 24, 2023
1 parent 5dce4a9 commit fbe9154
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ app.use(express.static(path.join(__dirname, "public")));

app.use(i18n({
"translationsPath": path.join(__dirname, "i18n"),
"siteLangs": ["en", "es"],
"locales": ["en", "es"],
"siteLangs": ["en", "es", "de"],
"locales": ["en", "es", "de"],
"cookieLangName": "locale",
"defaultLang": "en",
"textsVarName": "i18n"
Expand Down
4 changes: 2 additions & 2 deletions controllers/api_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ exports.checkParticipantSafe = async (req, res, next) => {
const user = await authenticate(email, password, token);

if (user) {
if (!req.escapeRoom.forceLang && user.lang && i18n.lang !== user.lang && (user.lang === "es" || user.lang === "en")) {
if (!req.escapeRoom.forceLang && user.lang && i18n.lang !== user.lang && (user.lang === "es" || user.lang === "en" || user.lang === "de")) {
// eslint-disable-next-line global-require
res.locals.i18n_lang = user.lang === "es" ? "es" : "en";
res.locals.i18n_lang = ["en", "es", "de"].includes(user.lang) ? user.lang : "en";
// eslint-disable-next-line global-require
res.locals.i18n_texts = require(`../i18n/${res.locals.i18n_lang}`);
res.locals.i18n = res.locals.i18n_texts;
Expand Down
15 changes: 11 additions & 4 deletions controllers/escapeRoom_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const {nextStep, prevStep} = require("../helpers/progress");
const {saveInterface, getERPuzzles, paginate, validationError} = require("../helpers/utils");
const es = require("../i18n/es");
const en = require("../i18n/en");
const de = require("../i18n/de");

const LANGUAGE_FILES = {
en,
es,
de
};

// Autoload the escape room with id equals to :escapeRoomId
exports.load = async (req, res, next, escapeRoomId) => {
Expand All @@ -19,8 +26,8 @@ exports.load = async (req, res, next, escapeRoomId) => {
if (res.locals) {
if (!req.session || req.session && req.session.user && req.session.user.isStudent) {
if (escapeRoom.forceLang && req.cookies && req.cookies.locale !== escapeRoom.forceLang) {
res.locals.i18n_texts = escapeRoom.forceLang === "es" ? es : en;
res.locals.i18n_lang = escapeRoom.forceLang === "es" ? "es" : "en";
res.locals.i18n_texts = LANGUAGE_FILES[escapeRoom.forceLang] || en;
res.locals.i18n_lang = Object.keys(LANGUAGE_FILES).includes(escapeRoom.forceLang) ? escapeRoom.forceLang : "en";
res.locals.i18n = res.locals.i18n_texts;
}
}
Expand Down Expand Up @@ -121,7 +128,7 @@ exports.create = async (req, res) => {
const escapeRoom = models.escapeRoom.build({title, subject, duration, "forbiddenLateSubmissions": forbiddenLateSubmissions === "on", invitation, description, supportLink, "scope": scope === "private", "teamSize": teamSize || 0, authorId, forceLang}); // Saves only the fields question and answer into the DDBB
const {i18n} = res.locals;

escapeRoom.forceLang = forceLang === "en" || forceLang === "es" ? forceLang : null;
escapeRoom.forceLang = Object.keys(LANGUAGE_FILES).includes(forceLang) ? forceLang : null;

try {
const er = await escapeRoom.save({"fields": ["title", "teacher", "subject", "duration", "description", "forbiddenLateSubmissions", "scope", "teamSize", "authorId", "supportLink", "invitation", "forceLang"]});
Expand Down Expand Up @@ -193,7 +200,7 @@ exports.update = async (req, res) => {
escapeRoom.invitation = body.invitation !== undefined ? body.invitation.toString() : undefined;
escapeRoom.scope = body.scope === "private";
escapeRoom.teamSize = body.teamSize || 0;
escapeRoom.forceLang = body.forceLang === "en" || body.forceLang === "es" ? body.forceLang : null;
escapeRoom.forceLang = Object.keys(LANGUAGE_FILES).includes(body.forceLang) ? body.forceLang : null;
const progressBar = body.progress;

try {
Expand Down
6 changes: 3 additions & 3 deletions io.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ exports.createServer = (server, sessionMiddleware) => {
const {escapeRoomId, lang, waiting, "turnId": teacherTurnId} = getInfoFromSocket(socket);
let forceLanguage = "en";

if (lang && (lang === "es" || lang === "en")) {
if (lang && (lang === "es" || lang === "en" || lang === "de")) {
forceLanguage = lang;
}
let i18n = require(`./i18n/${forceLanguage}`);

if (user) {
if (user.lang && (user.lang === "es" || user.lang === "en")) {
if (user.lang && (user.lang === "es" || user.lang === "en" || user.lang === "de")) {
i18n = require(`./i18n/${user.lang}`);
}
const {token, username} = user;
const {"turnId": studentTurnId, teamId, participation, erState, errorMsg, language, teamInstructions} = await checkAccess(user, escapeRoomId, i18n, waiting);

if (language && (language === "es" || language === "en")) {
if (language && (language === "es" || language === "en" || language === "de")) {
i18n = require(`./i18n/${language}`);
}

Expand Down
2 changes: 1 addition & 1 deletion models/escapeRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = function (sequelize, DataTypes) {
"forceLang": {
"type": DataTypes.STRING,
"allowNull": true,
"validate": {"isIn": [["en", "es"]]}
"validate": {"isIn": [["en", "es", "de"]]}
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function (sequelize, DataTypes) {
"lang": {
"type": DataTypes.STRING,
"allowNull": true,
"validate": {"isIn": [["en", "es"]]}
"validate": {"isIn": [["en", "es", "de"]]}
}
});

Expand Down
2 changes: 1 addition & 1 deletion public/apps/digitalLock/dist/vendors/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function readURLparams(){
}

function isValidLanguage(language){
return ((typeof language === "string") && (["en", "es"].indexOf(language) !== -1));
return ((typeof language === "string") && (["en", "es", "de"].indexOf(language) !== -1));
}

export function getTrans(s, params){
Expand Down
2 changes: 1 addition & 1 deletion public/apps/digitalLock/scorm12/vendors/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function readURLparams(){
}

function isValidLanguage(language){
return ((typeof language === "string") && (["en", "es"].indexOf(language) !== -1));
return ((typeof language === "string") && (["en", "es", "de"].indexOf(language) !== -1));
}

export function getTrans(s, params){
Expand Down
2 changes: 1 addition & 1 deletion public/apps/digitalLock/scorm2004/vendors/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function readURLparams(){
}

function isValidLanguage(language){
return ((typeof language === "string") && (["en", "es"].indexOf(language) !== -1));
return ((typeof language === "string") && (["en", "es", "de"].indexOf(language) !== -1));
}

export function getTrans(s, params){
Expand Down
3 changes: 2 additions & 1 deletion public/scorm/SCORM_Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ function SCORM_Player (options) {

return typeof language === "string" && [
"en",
"es"
"es",
"de"
].indexOf(language) != -1;

}
Expand Down
3 changes: 2 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<% } %>
<ul class="langs">
<li><a class="<%=(lang=="en"?"active":"")%>" href="/?clang=en">en</a></li> /
<li><a class="<%=(lang=="es"?"active":"")%>" href="/?clang=es">es</a></li>
<li><a class="<%=(lang=="es"?"active":"")%>" href="/?clang=es">es</a></li> /
<li><a class="<%=(lang=="de"?"active":"")%>" href="/?clang=de">de</a></li>
</ul>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions views/partials/_form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<option value="" <%=escapeRoom.forceLang ? "" : "selected" %>><%=i18n.langs["dontForce"]%> </option>
<option value="en" <%=escapeRoom.forceLang == "en" ? "selected" : "" %>><%=i18n.langs["en"]%></option>
<option value="es"<%=escapeRoom.forceLang == "es" ? "selected" : "" %>><%=i18n.langs["es"]%></option>
<option value="de" <%=escapeRoom.forceLang == "de" ? "selected" : "" %>><%=i18n.langs["de"]%></option>
</select>
</div>

Expand Down
1 change: 1 addition & 0 deletions views/users/_form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<select class="customInput" id="lang" name="lang" required autocomplete="off">
<option value="en" <%=(user.lang == "en" || (!user.lang && (i18n.lang === "en"))) ? "selected" :""%>><%=i18n.langs.en%></option>
<option value="es" <%=(user.lang == "es" || (!user.lang && (i18n.lang === "es"))) ? "selected" :""%>><%=i18n.langs.es%></option>
<option value="de" <%=(user.lang == "de" || (!user.lang && (i18n.lang === "de"))) ? "selected" :""%>><%=i18n.langs.de%></option>
</select>
</label>
</div>
Expand Down

0 comments on commit fbe9154

Please sign in to comment.