{"record":{"id":"52cc05a3789f1cd6","repo":"balderdashy/sails","slug":"i18n-hook-has-disabled-itself-due-to-misconfigurat","errorCode":null,"errorMessage":"i18n hook has disabled itself due to misconfiguration -- returning input string as-is.  Set `sails.config.i18n.locales` to activate i18n.","messagePattern":"i18n hook has disabled itself due to misconfiguration -- returning input string as-is\\.  Set `sails\\.config\\.i18n\\.locales` to activate i18n\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/hooks/i18n/index.js","lineNumber":75,"sourceCode":"        sails.config.i18n.locales = [sails.config.i18n.defaultLocale].concat(_.without(sails.config.i18n.locales, sails.config.i18n.defaultLocale));\n      }\n\n    },\n\n    initialize: function(cb) {\n\n      var self = this;\n\n      // If the array of locales is empty, then bail out now.\n      // (There's nothing for us to do in this hook.)\n      if (sails.config.i18n.locales.length === 0) {\n        sails.log.verbose('Skipping i18n hook because configured locales (`sails.config.i18n.locales`) is an empty array.');\n\n        // Delete sails.hooks.i18n so that checks like `if (sails.hooks.i18n)` come back falsey.\n        delete sails.hooks.i18n;\n\n        // Add __ and i18n functions that just pass through the string (and return a warning).\n        sails.__ = sails.i18n = function(str) { sails.log.warn('i18n hook has disabled itself due to misconfiguration -- returning input string as-is.  Set `sails.config.i18n.locales` to activate i18n.');  return str; };\n        // Add passthru __ and i18n to res.locals.\n        sails.on('router:before', function () {\n          sails.router.bind('all /*', function addLocalizationMethod (req, res, next) {\n            res.locals.__ = res.locals.i18n = sails.__;\n            return next();\n          });\n\n        });//</sails.on>\n\n        return cb();\n      }//-•\n\n      // Determine the abs path to the locales dir, resolving relative from the appPath.\n      // (supports absolute or relative path)\n      resolvedLocalesDirectory = path.resolve(sails.config.appPath, sails.config.i18n.localesDirectory);\n\n      // Override logger while initializing i18n-2, since it uses console function directly.\n      // We'll just buffer any messages and replay them when i18n-2 is done (or fails) initializing.","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/hooks/i18n/index.js#L57-L93","documentation":"When the i18n hook cannot be used because `sails.config.i18n.locales` is unset or an empty array, the hook disables itself: it deletes `sails.hooks.i18n` and replaces `sails.__`/`sails.i18n` with pass-through functions that log this warning and return the input string unchanged. No translation is performed; every localized string comes back as-is.","triggerScenarios":"Booting Sails with `sails.config.i18n.locales` undefined or set to `[]`, then calling `sails.__('key')`, `res.i18n()`, or using `res.locals.__` in a view.","commonSituations":"Fresh Sails 1.x projects where config/i18n.js was deleted or emptied (locales defaults were removed), or teams intentionally disabling i18n without realizing every `__()` call will warn and skip translation.","solutions":["Set `locales` to a non-empty array in config/i18n.js, e.g. `locales: ['en', 'es']`","If i18n is truly unwanted, silence the passthrough by overriding `sails.__` in your own hook or removing all `__()` calls from code and views","Restore the default config/i18n.js from the Sails app template if it was accidentally deleted"],"exampleFix":"// before\nmodule.exports.i18n = { locales: [] };\n// after\nmodule.exports.i18n = { locales: ['en', 'es'] };","handlingStrategy":"validation","validationCode":"if (!Array.isArray(sails.config.i18n.locales) || sails.config.i18n.locales.length === 0) {\n  sails.config.i18n.locales = ['en']; // or fix config before lift\n}","typeGuard":"function hasLocales(cfg) {\n  return cfg && cfg.i18n && Array.isArray(cfg.i18n.locales) && cfg.i18n.locales.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Keep the default config/i18n.js with at least one locale","Add a lift-time config check that asserts locales is a non-empty array when __() is used","Avoid deleting stock config files during upgrades"],"tags":["i18n","config","sails"],"backgroundTag":"misconfigured-i18n-locales","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}