From ce95c84d02d80ba25364434757912ce20102f52d Mon Sep 17 00:00:00 2001 From: Mike McNeil Date: Tue, 20 Mar 2018 21:33:04 -0500 Subject: [PATCH] Update comments to reflect that req.setLocale() is fully supported as of Sails v1.0 and beyond. --- lib/hooks/i18n/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/hooks/i18n/index.js b/lib/hooks/i18n/index.js index 5f473d5dc..1ce9b403c 100644 --- a/lib/hooks/i18n/index.js +++ b/lib/hooks/i18n/index.js @@ -182,12 +182,15 @@ module.exports = function(sails) { // Mix translation capabilities into res.locals. i18nFactory.registerMethods(res.locals, req); - // Add `i18n` method as alias to `__` for backwards compatibility. - res.locals.i18n = res.locals.__; + // Add `setLocale()` method for convenience. + // (This is documented and fully supported as of Sails v1.0 and beyond.) + req.setLocale = req.i18n.setLocale.bind(req.i18n); - // Add `getLocale()` and `setLocale()` methods to `req` for backwards compatibility. + // For backwards compatibility: + // • Add `i18n` method as alias to `__` + // • Add `getLocale()` method to `req` + res.locals.i18n = res.locals.__; req.getLocale = req.i18n.getLocale.bind(req.i18n); - req.setLocale = req.i18n.setLocale.bind(req.i18n); } catch (e) { // Seeing as we have a valid i18n singleton already, the