diff --git a/src/routes.js b/src/routes.js
index cf34a6d..b8677a2 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -106,11 +106,13 @@ module.exports = (app, utils) => {
return res.redirect(back)
})
- app.post('/wiki/Special::DownloadAsPdf', (req, res, next) => {
+ app.post(/DownloadAsPdf/, (req, res, next) => {
if(!req.body.page) {
return res.redirect('/')
}
- return res.redirect(`/w/index.php?title=Special%3ADownloadAsPdf&page=${req.body.page}&action=redirect-to-electron`)
+ let lang = req.body.lang || req.cookies.default_lang || config.default_lang
+
+ return res.redirect(`/w/index.php?title=Special%3ADownloadAsPdf&page=${req.body.page}&action=redirect-to-electron&lang=${lang}`)
})
}
diff --git a/src/utils.js b/src/utils.js
index aca2b79..004b09f 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -171,6 +171,18 @@ module.exports = function(redis) {
const wiki_href_regx = /(href=\"(https:|http:|)\/\/([A-z.-]+\.)?(wikipedia.org|wikimedia.org|wikidata.org|mediawiki.org))/gm
data.html = data.html.replace(wiki_href_regx, `href="${protocol}${config.domain}`)
+ /**
+ * If we are on DownloadAsPdf page, we have to inject a input which
+ * holds the language value. Without this input, we can't access the
+ * language (not avail from the POST data).
+ * See more on https://codeberg.org/orenom/Wikiless/issues/9
+ */
+ if(url.includes('%3ADownloadAsPdf')) {
+ let lang_input = ``
+ let replace_str = ` {
if(error) {
console.log(`Error setting the ${url} key to Redis. Error: ${error}`)