i18n: Fix urls while not / exists

This commit is contained in:
Samuel Ortion 2022-08-29 07:26:21 +02:00
parent d590582a85
commit 0498ea8541
4 changed files with 20 additions and 7 deletions

2
app.js
View File

@ -86,6 +86,8 @@ const csrfProtection = csrf({ cookie: true });
app.use(csrfProtection);
app.use(/\/(fr|en)/i, indexRouter);
app.use(/\/(fr|en)\/auth/i, authRouter);
app.use("/", indexRouter);
app.use("/auth", authRouter);
// catch 404 and forward to error handler
app.use(function (req, res, next) {

View File

@ -7,7 +7,10 @@ function indexPage(req, res) {
}
function loginPage(req, res) {
res.render('auth/login');
res.render('auth/login', {
title: req.i18n.__("SoundBirder - Login"),
locale: req.i18n.locale
});
}
function login(req, res) {
@ -19,11 +22,14 @@ function logout(req, res) {
}
function registerPage(req, res) {
res.render('auth/register');
res.render('auth/register', {
title: req.i18n.__("SoundBirder - Register"),
locale: req.i18n.locale
});
}
function register(req, res) {
}
function forgotPassword(req, res) {

View File

@ -2,12 +2,16 @@
function getIndex(req, res) {
res.render('index', {
title: 'SoundBirder',
csrf_token: req.csrfToken()
csrf_token: req.csrfToken(),
locale: req.i18n.locale
});
}
function getAbout(req, res) {
res.render('about', { title: 'About SoundBirder' });
res.render('about', {
title: 'About SoundBirder',
locale: req.i18n.locale
});
}
module.exports = {

View File

@ -10,11 +10,12 @@ html
header
h1= title
nav
- var i18n_prefix = locale ? '/' + locale : ''
ul
li
a(href="/") #{ __("Game") }
a(href=`${i18n_prefix}/`) #{ __("Game") }
li
a(href="/about") #{ __("About") }
a(href=`${i18n_prefix}/about`) #{ __("About") }
main
block content
footer