www: Add i18n /en|fr/ urls

This commit is contained in:
Samuel Ortion 2022-08-28 09:48:24 +02:00
parent 585e578e48
commit 4bfa6cfe16
3 changed files with 35 additions and 18 deletions

26
app.js
View File

@ -42,16 +42,30 @@ i18n.expressBind(app, {
cookieName: 'locale'
});
app.use('/dist/leaflet', express.static('node_modules/leaflet/dist'));
app.use('/dist/feather', express.static('node_modules/feather-icons/dist'));
app.use('/dist/axios', express.static('node_modules/axios/dist'));
app.use(function (req, res, next) {
req.i18n.setLocaleFromQuery();
req.i18n.setLocaleFromCookie();
next();
});
app.all('*', function(req, res, next) {
// set locale
var rxLocale = /^\/(fr|en)/i;
if(rxLocale.test(req.url)){
const arr = rxLocale.exec(req.url);
const locale=arr[1];
req.i18n.setLocale(locale);
} else {
req.i18n.setLocale('en');
}
// add extra logic
next();
});
app.use('/dist/leaflet', express.static('node_modules/leaflet/dist'));
app.use('/dist/feather', express.static('node_modules/feather-icons/dist'));
app.use('/dist/axios', express.static('node_modules/axios/dist'));
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header(
@ -65,8 +79,8 @@ app.use('/api/0', apiRouter);
const csrfProtection = csrf({ cookie: true });
app.use(csrfProtection);
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use(/\/(fr|en)/i, indexRouter);
app.use(/\/(fr|en)\/auth/i, authRouter);
// catch 404 and forward to error handler
app.use(function (req, res, next) {

View File

@ -1 +1,4 @@
{}
{
"Game": "Game",
"About": "About"
}

View File

@ -1,4 +1,4 @@
{
"Home": "Home",
"About": "About"
"Home": "Inicio",
"About": "Acerca de",
}