Download ADOOR_ACE/node_modules/express-middleware/src/middleware/i18n.js from thisisAce/adoor-store: direct link, hf CLI and curl.
- Browser
- Download file 881 Bytes
-
https://huggingface.co/thisisAce/adoor-store/resolve/main/ADOOR_ACE/node_modules/express-middleware/src/middleware/i18n.js
- Command line
-
hf download hf://thisisAce/adoor-store/ADOOR_ACE/node_modules/express-middleware/src/middleware/i18n.js
-
curl -L -o i18n.js https://huggingface.co/thisisAce/adoor-store/resolve/main/ADOOR_ACE/node_modules/express-middleware/src/middleware/i18n.js
881 Bytes
| ; | |
| const wrap = require('co-express'); | |
| module.exports = setup; | |
| // // // | |
| /** | |
| * Translation Middleware | |
| * | |
| * This function checks if a res.body has been set and will | |
| * translate all found keys. | |
| * | |
| * @param {Object} i18n library configured instance | |
| * @return {Function} middleware | |
| */ | |
| function setup(i18n) { | |
| /** | |
| * Middleware | |
| * @param {Object} req Express request | |
| * @param {Object} res Express response | |
| * @param {Function} next Express next handler | |
| * @returns {void} | |
| */ | |
| return wrap(function* middleware(req, res, next) { | |
| if (!i18n) { | |
| throw new Error( | |
| 'Missing i18n dependency, i18n middleware should be initialized with a configured instance of i18n' | |
| ); | |
| } | |
| if (res.body) { | |
| res.body = yield i18n.translate(res.body, req.language); | |
| return res.json(res.body); | |
| } | |
| return next(); | |
| }); | |
| } | |