- Expand SUPPORTED_LANGS from 5 to all 31 languages matching backend - Expand LANG_NAMES to include all 31 native language names - Add RTL_LANGS set (ar, fa, ur) for multi-language RTL support - Fix applyTranslations() to always write resolved value (clears stale translations when switching back to English) - Fix loadTranslations() to clear translations on fetch failure/error - Add monotonic _langRequestId token to prevent out-of-order async resolution race (A->B->A scenario) - Wrap localStorage access in try/catch for privacy mode environments - Validate stored language code against SUPPORTED_LANGS on init - Always set document.documentElement.dir/lang on init (not just RTL) - Add scrollable dropdown for 31 languages (max-height: 320px) - Fix backend i18n route to use LANGUAGE_META instead of hardcoded 5-lang map - Rebuild dist bundles Codex grade: A (urn:ump:kicey7d7dnockmlk547cmm4qbdvygcj3g6waasrqv2yckbzem5bq) 1775/1775 tests pass
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
/**
|
|
* DC-077: i18n route — serves translations and language metadata
|
|
*/
|
|
const express = require('express');
|
|
const { ok } = require('../src/utils/responses');
|
|
const i18n = require('../src/utilities/i18n');
|
|
|
|
module.exports = function() {
|
|
const router = express.Router();
|
|
|
|
// GET /api/v1/i18n/languages — list supported languages
|
|
router.get('/i18n/languages', (req, res) => {
|
|
const meta = i18n.getAllLanguages();
|
|
ok(res, {
|
|
languages: i18n.getSupportedLanguages().map(code => {
|
|
const m = meta[code] || {};
|
|
return { code, name: m.name || code, flag: m.flag || '🌐', rtl: !!m.rtl };
|
|
}),
|
|
default: i18n.DEFAULT_LANGUAGE,
|
|
});
|
|
});
|
|
|
|
// GET /api/v1/i18n/translations/:lang — get all translations for a language
|
|
router.get('/i18n/translations/:lang', (req, res) => {
|
|
const lang = req.params.lang;
|
|
if (!i18n.isSupported(lang)) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: `Unsupported language: ${lang}`,
|
|
supported: i18n.getSupportedLanguages(),
|
|
});
|
|
}
|
|
ok(res, { lang, translations: i18n.TRANSLATIONS[lang] || {} });
|
|
});
|
|
|
|
return router;
|
|
};
|