Changeset eb5f978 in Klonkt for src/routes


Ignore:
Timestamp:
06/27/2026 01:58:39 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
98fe58a
Parents:
0960c1d
Message:

feat(changelog): i18n the public changelog (English base + nl/de)

  • CHANGELOG.md — now the English base (translated from Dutch), the source of truth going forward.
  • CHANGELOG.nl.md — the previous Dutch changelog, kept as the Dutch translation.
  • CHANGELOG.de.md — German translation.
  • routes/changelog.js — serve CHANGELOG.<lang>.md for the visitor's language, fall back to the English base; title/empty-message via i18n.
  • services/i18n.js — changelog.title + changelog.empty (nl/en/de).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/changelog.js

    r0960c1d reb5f978  
    22 * Public changelog / release page.
    33 *
    4  * GET /changelog  -> renders CHANGELOG.md (the source of truth for releases).
     4 * GET /changelog  -> renders the changelog in the visitor's language:
     5 *   CHANGELOG.<lang>.md if a translation exists, else CHANGELOG.md (English base).
    56 */
    67
     
    1112import { renderPage } from '../middleware/render.js';
    1213import { MarkdownService } from '../services/MarkdownService.js';
     14import { resolveLang, t } from '../services/i18n.js';
     15import { getSetting } from '../services/SettingsService.js';
    1316
    1417const router = express.Router();
    1518const __dirname = path.dirname(fileURLToPath(import.meta.url));
    16 const CHANGELOG_PATH = path.join(__dirname, '..', '..', 'CHANGELOG.md');
     19const ROOT = path.join(__dirname, '..', '..');
    1720
    1821router.get('/changelog', (req, res) => {
    19   let html;
    20   try {
    21     html = MarkdownService.render(fs.readFileSync(CHANGELOG_PATH, 'utf8'));
    22   } catch {
    23     html = '<p>Geen wijzigingenoverzicht beschikbaar.</p>';
     22  const lang = resolveLang(req, {
     23    userLang: req.session && req.session.user && req.session.user.lang,
     24    defaultLang: getSetting('default_lang'),
     25  });
     26  // Visitor's language if a translation exists, else the English base.
     27  const files = [path.join(ROOT, `CHANGELOG.${lang}.md`), path.join(ROOT, 'CHANGELOG.md')];
     28  let html = '';
     29  for (const f of files) {
     30    try { html = MarkdownService.render(fs.readFileSync(f, 'utf8')); break; } catch { /* try next */ }
    2431  }
     32  if (!html) html = `<p>${t(lang, 'changelog.empty')}</p>`;
    2533  renderPage(req, res, 'pages/changelog', {
    26     pageTitle: 'Wijzigingen',
     34    pageTitle: t(lang, 'changelog.title'),
    2735    bodyClass: 'on-changelog',
    2836    changelogHtml: html,
Note: See TracChangeset for help on using the changeset viewer.