main
|
Last change
on this file since 292734a was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago |
|
i18n: translate Dutch code comments to English across src/
Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.
Co-Authored-By: Claude <noreply@…>
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [834bcc3] | 1 | // Visitor language choice: /lang/:code sets the interface language in the session
|
|---|
| 2 | // and redirects back to where you came from. (Content stays in the author's language.)
|
|---|
| [03fa548] | 3 | import express from 'express';
|
|---|
| 4 | import { SUPPORTED } from '../services/i18n.js';
|
|---|
| [5e61b17] | 5 | import db from '../config/database.js';
|
|---|
| [03fa548] | 6 |
|
|---|
| 7 | const router = express.Router();
|
|---|
| 8 |
|
|---|
| 9 | router.get('/lang/:code', (req, res) => {
|
|---|
| 10 | const code = SUPPORTED.includes(req.params.code) ? req.params.code : 'nl';
|
|---|
| 11 | if (req.session) req.session.lang = code;
|
|---|
| [834bcc3] | 12 | // Logged in? Also save the choice on the account so it follows the user
|
|---|
| 13 | // across devices/sessions (not just this session cookie).
|
|---|
| [5e61b17] | 14 | if (req.session && req.session.user && req.session.user.id) {
|
|---|
| 15 | try {
|
|---|
| 16 | db.prepare('UPDATE users SET lang = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?').run(code, req.session.user.id);
|
|---|
| 17 | req.session.user.lang = code;
|
|---|
| [834bcc3] | 18 | } catch { /* lang column missing on an old DB → session-only, no breakage */ }
|
|---|
| [5e61b17] | 19 | }
|
|---|
| [834bcc3] | 20 | // Safe back URL: internal path only (no open redirect).
|
|---|
| [03fa548] | 21 | let back = (typeof req.query.r === 'string') ? req.query.r : '';
|
|---|
| 22 | if (!back.startsWith('/') || back.startsWith('//')) {
|
|---|
| 23 | try {
|
|---|
| 24 | const u = new URL(req.get('referer') || '');
|
|---|
| 25 | back = u.pathname + (u.search || '');
|
|---|
| 26 | } catch { back = '/'; }
|
|---|
| 27 | }
|
|---|
| 28 | res.redirect(back || '/');
|
|---|
| 29 | });
|
|---|
| 30 |
|
|---|
| 31 | export default router;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.