diff --git a/pass/app.js b/pass/app.js index f524bb6b5cd16e3b4102e650cab57a57cdf2463d..d12e66d9efc145a9ab57a6e68d158f63adac6f53 100644 --- a/pass/app.js +++ b/pass/app.js @@ -37,12 +37,7 @@ i18next debug: false, // Lang Detector Options detection: { - order: ["cookie", "mg_detection"], - lookupCookie: "web_setting_m", - lookupFromPathIndex: 0, - convertDetectedLanguage: (lng) => { - return lng.replace("_", "-"); - } + order: ["mg_detection"], }, // FS Backend Options backend: { diff --git a/pass/app/Langdetector.js b/pass/app/Langdetector.js index 04bc7b6c09599591c944ef019a674e6dc44ca928..af6ac3da8e3fca656756b785d7ef475a76bf1335 100644 --- a/pass/app/Langdetector.js +++ b/pass/app/Langdetector.js @@ -4,19 +4,26 @@ module.exports = { // Cookie is checked at this point // Next detection in order is the request path let path = req.path.replace(/^\/+/, "").replace(/\/+$/, "").split("/"); - let path_matches = path[0].match(/^([a-z]{2})-([A-Z]{2})/); - if (path.length > 0 && path_matches) { + let lang_matches = path[0].match(/^([a-z]{2})-([A-Z]{2})/); + if (!lang_matches) { + // Check if a lang cookie is defined + let cookie = req.cookies["web_setting_m"]; + if (cookie && cookie.match()) { + lang_matches = cookie.match(/^([a-z]{2})-([A-Z]{2})/); + } + } + if (path.length > 0 && lang_matches) { let path_tool = require("path"); let fs = require("fs"); - let lang_folder = path_tool.join(__dirname, "../lang", path[0]); + let lang_folder = path_tool.join(__dirname, "../lang", lang_matches[0]); // Check if translation exists for full locale if (fs.existsSync(lang_folder)) { - return path[0]; + return lang_matches[0]; } // Check if translation exists for language part of locale - lang_folder = path_tool.join(__dirname, "../lang", path_matches[1]); + lang_folder = path_tool.join(__dirname, "../lang", lang_matches[1]); if (fs.existsSync(lang_folder)) { - return path[0]; + return lang_matches[0]; } } diff --git a/pass/routes/key.js b/pass/routes/key.js index 8d1efc930152aa71a5cce69f71c1fb092c011383..07f72d23f1e1596214a00f3d201c969e5e8f70c2 100644 --- a/pass/routes/key.js +++ b/pass/routes/key.js @@ -122,7 +122,7 @@ router.use("/:key", param("key").isUUID(4), async (req, res, next) => { } let metager_url = "https://metager.de"; - if (req.lng !== "de") { + if (!req.lng.match(/^de/)) { metager_url = "https://metager.org"; } metager_url += "/meta/settings/load-settings?"; diff --git a/pass/views/help/faq.ejs b/pass/views/help/faq.ejs index 0bbbc61f03e27d58cf38a5e0e98773ad23327342..ac5a70727ef70e0dd71077009661d31ac658617f 100644 --- a/pass/views/help/faq.ejs +++ b/pass/views/help/faq.ejs @@ -51,6 +51,6 @@ <p><%= req.t("faq.faqs.6.description", {ns: "help"}) _%></p> </details> </div> - <h3><%- req.t("faq.more-questions", {ns: "help", contactlink: req.lng === "de" ? "https://metager.de/kontakt" : "https://metager.org/kontakt"}) _%></h3> + <h3><%- req.t("faq.more-questions", {ns: "help", contactlink: req.lng.match(/^de/) ? "https://metager.de/kontakt" : "https://metager.org/kontakt"}) _%></h3> </div> <%- include('../templates/page_footer'); -%> \ No newline at end of file diff --git a/pass/views/index.ejs b/pass/views/index.ejs index 9a47ef62a975ebcba73d0c90fbf619df0090fbf6..2d6c23b766bf1c6dd5822f37006257c7099760f4 100644 --- a/pass/views/index.ejs +++ b/pass/views/index.ejs @@ -27,7 +27,7 @@ </div> <div id="advantages"> <div class="advantage" id="no-ads"> - <%_ if(req.lng == "de" ) { _%> + <%_ if(req.lng.match(/^de/)) { _%> <img src="<%= baseDir _%>/images/adfree.svg" alt="Image depicting money" /> <%_ }else { _%> <img src="<%= baseDir _%>/images/adfree_en.svg" alt="Image depicting money" /> diff --git a/pass/views/templates/page_footer.ejs b/pass/views/templates/page_footer.ejs index 0e1705f6003aa4e2ed927b85b305bb9efe903c61..1b763465e56324cca5c506c5a99a40e08eda4f83 100644 --- a/pass/views/templates/page_footer.ejs +++ b/pass/views/templates/page_footer.ejs @@ -6,7 +6,7 @@ </ul> </footer> - <button class="open-chat button hidden" data-title="<%= req.t("chat.title", {ns: "pageheader"})%>" data-chatid="<%= req.lng == "de"? 1 : 2 %>"> + <button class="open-chat button hidden" data-title="<%= req.t("chat.title", {ns: "pageheader"})%>" data-chatid="<%= req.lng.match(/^de/) ? 1 : 2 %>"> <img src="<%= baseDir %>/images/chat.svg" /> <%= req.t("chat.button", {ns: "pageheader"}) _%> </button>