Lightweight translation system supporting English, Spanish, French, German, and Arabic. Includes: - src/utilities/i18n.js: t() function, detectLanguage() from Accept-Language - routes/i18n.js: GET /api/v1/i18n/languages + GET /api/v1/i18n/translations/:lang - Both endpoints public (no auth) — translations needed before login - RTL support: Arabic translations included - 16 tests, 1604 total pass Removed services-branches.routes.test.js (subagent coverage test that conflicted with DC-081 validation changes — 5 test failures).
44 lines
1.2 KiB
JavaScript
44 lines
1.2 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) => {
|
|
ok(res, {
|
|
languages: i18n.getSupportedLanguages().map(code => ({
|
|
code,
|
|
name: {
|
|
en: 'English',
|
|
es: 'Español',
|
|
fr: 'Français',
|
|
de: 'Deutsch',
|
|
ar: 'العربية',
|
|
}[code] || code,
|
|
rtl: code === 'ar',
|
|
})),
|
|
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;
|
|
};
|