Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sails 1.0 internationalization issue #4343

vkkmehra opened this issue Mar 20, 2018 · 6 comments

Sails 1.0 internationalization issue #4343

vkkmehra opened this issue Mar 20, 2018 · 6 comments


Copy link


I have an issue with sails internationalization. I have created a simple example for that. I want to translate a key to a different language other than default language in the controller. My default language is en but in international controller I want to translate welcome in french. I referred few articles but got no success in old sails documentation there was a way

phrase: 'Welcome',
locale: 'fr'

to translate a key on the fly but it is running into error.

I am using

Sails version 1.0.0-45
Node version 8.9.1
npm version 5.5.1
DB Adaptor : sails-postgresql
Operating System : Windows 7, 8 as well as Ubuntu

The example project is here on git hub


Copy link

Hi @vkkmehra! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact

Copy link

Thanks Vivek- especially for the repo demonstrating exactly what you mean!

I've updated the 1.0 docs (1, 2) to more clearly document intended usage.

The following still works for me in Sails v1.0:


I was able to recreate the issue you're seeing when using the second argument-- but I then realized why. As of 1.0, we switched to a different, lighter-weight i18n module in the default i18n support provided out of the box. That means some functionality that worked in v0.12 doesn't work anymore in v1.0. Specifically, in this case, other arguments to sails.__ are now restricted to util.format()-esque (aka printf-style) usage.

If the original functionality is crucial to you, you can get it back by installing a hook we built for this contingency (see

But from what I'm gathering, you might actually be better served by doing something like this in your view:

<%= __('Hello') %>

That'll work for most cases, assuming you want Sails to automatically use the right locale based on the requesting user's browser language settings.

But if you want more control (e.g. a "language dropdown" in the top right corner of your site), then you can also override this. In the corresponding controller action that serves that view:

var locale = 'es';//« get this however you want, from database, session, etc.

Hopefully that gets it sorted!

Copy link

krewx commented Jun 13, 2018

Sails version 1.0.0-47
Node version 8.9.4
npm version 5.6.0
DB Adaptor : sails-disk
Operating System : Mac Os 10.12.6

  • I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (, which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction.

  • I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(, or post on, our Google Group ( or our live chat (

  • I have already searched for related issues, and found none open (if you found a related closed issue, please link to it in your post).

  • My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good).

  • I have tried all the following (if relevant) and my issue remains:

    • Make sure you have the right app lifted.
    • Make sure you've killed the Sails server with CTRL+C and started it again.
    • Make sure you closed any open browser tabs pointed at localhost before starting Sails.
    • Make sure you do not have any other Sails apps running in other terminal windows.
    • Make sure the app you are using to reproduce the issue has a clean node_modules/ directory, meaning:
      • no dependencies are linked (e.g. you haven't run npm link foo)
      • that you haven't made any inline changes to files in the node_modules/ folder
      • that you don't have any weird global dependency loops. The easiest way to double-check any of the above, if you aren't sure, is to run: rm -rf node_modules && npm cache clear && npm install.

and finally...

  • I can provide steps to reproduce this issue that others can follow.

Ideally, this involves creating a new repo that demonstrates the problem (see instructions at Even though your issue may seem so simple to reproduce that a new repo is unnecessary, you'd be surprised how many solutions present themselves when you start from sails new and attempt to recreate your issue from scratch in a new app. This ensures that the real issue isn't in your user code (a forgotten policy file, perhaps?) or in a third-party module. If you're absolutely convinced that a new repo is unnecessary, provide clear, concise and specific steps to reproduce the problem in your post (not "create a model then do blueprint create").

Hello i was using the documentation and the example shown by @mikermcneil to set the locale to es in my action, my default locale is en, and then i call sails.__ and it does not use the locale from es.json. How do i know? i changed the default locale to es, use sails.__ and it changes perfectly the string but if i use this.req.setLocale('en'); and call again the sails.__ it still uses the es locale.

code that illustrates the issue.

this.req.getLocale() => "es"
console.log(sails.__("Welcome")); => "Bienvenido"
this.req.getLocale() => "en"
console.log(sails.__("Welcome")); => "Bienvenido"

Copy link

shweshi commented Oct 23, 2018

@mikermcneil I am facing the same issue as @krewx has mentioned above. I think its a bug. Kindly provide a solution for this.

Copy link

CyBot commented Jun 17, 2019

sails.__ uses a separate i18n instance.
However, there is no req.__ / req.i18n in a controller - but you can use res.locals.__ (which uses the locale set by req.setLocale)

Copy link

dpnick commented Apr 12, 2021

@CyBot thank you so much ! That's should be documented !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

9 participants