Sails 1.0 internationalization issue #4343
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
to translate a key on the fly but it is running into error.
I am using
Sails version 1.0.0-45
The example project is here on git hub https://github.com/vkkmehra/international
The text was updated successfully, but these errors were encountered:
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 email@example.com
Thanks Vivek- especially for the repo demonstrating exactly what you mean!
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
If the original functionality is crucial to you, you can get it back by installing a hook we built for this contingency (see https://github.com/balderdashy/sails-docs/blob/af687db90049661cb0f9a25c586843cd1c4ba34c/upgrading/To1.0.md#i18n)
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. this.req.setLocale('es');
Hopefully that gets it sorted!
Sails version 1.0.0-47
Ideally, this involves creating a new repo that demonstrates the problem (see instructions at http://bit.ly/sails-issue-repro). 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
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.