balderdashy/sails · warning

i18n hook has disabled itself due to misconfiguration -- ret

Error message

i18n hook has disabled itself due to misconfiguration -- returning input string as-is.  Set `sails.config.i18n.locales` to activate i18n.

What it means

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.

Source

Thrown at lib/hooks/i18n/index.js:75

        sails.config.i18n.locales = [sails.config.i18n.defaultLocale].concat(_.without(sails.config.i18n.locales, sails.config.i18n.defaultLocale));
      }

    },

    initialize: function(cb) {

      var self = this;

      // If the array of locales is empty, then bail out now.
      // (There's nothing for us to do in this hook.)
      if (sails.config.i18n.locales.length === 0) {
        sails.log.verbose('Skipping i18n hook because configured locales (`sails.config.i18n.locales`) is an empty array.');

        // Delete sails.hooks.i18n so that checks like `if (sails.hooks.i18n)` come back falsey.
        delete sails.hooks.i18n;

        // Add __ and i18n functions that just pass through the string (and return a warning).
        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; };
        // Add passthru __ and i18n to res.locals.
        sails.on('router:before', function () {
          sails.router.bind('all /*', function addLocalizationMethod (req, res, next) {
            res.locals.__ = res.locals.i18n = sails.__;
            return next();
          });

        });//</sails.on>

        return cb();
      }//-•

      // Determine the abs path to the locales dir, resolving relative from the appPath.
      // (supports absolute or relative path)
      resolvedLocalesDirectory = path.resolve(sails.config.appPath, sails.config.i18n.localesDirectory);

      // Override logger while initializing i18n-2, since it uses console function directly.
      // We'll just buffer any messages and replay them when i18n-2 is done (or fails) initializing.

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Set `locales` to a non-empty array in config/i18n.js, e.g. `locales: ['en', 'es']`
  2. If i18n is truly unwanted, silence the passthrough by overriding `sails.__` in your own hook or removing all `__()` calls from code and views
  3. Restore the default config/i18n.js from the Sails app template if it was accidentally deleted

Example fix

// before
module.exports.i18n = { locales: [] };
// after
module.exports.i18n = { locales: ['en', 'es'] };
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(sails.config.i18n.locales) || sails.config.i18n.locales.length === 0) {
  sails.config.i18n.locales = ['en']; // or fix config before lift
}

Type guard

function hasLocales(cfg) {
  return cfg && cfg.i18n && Array.isArray(cfg.i18n.locales) && cfg.i18n.locales.length > 0;
}

Prevention

When it happens

Trigger: Booting Sails with `sails.config.i18n.locales` undefined or set to `[]`, then calling `sails.__('key')`, `res.i18n()`, or using `res.locals.__` in a view.

Common situations: 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.

Related errors


AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01). Data as JSON: /api/errors/52cc05a3789f1cd6. Report an issue: GitHub.