balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

__ or i18n not available in handlebar #7290

Open iamaamir opened 1 year ago

iamaamir commented 1 year ago

Node version: v18.0.0 Sails version (sails): 1.4.0 ORM hook version (sails-hook-orm): Sockets hook version (sails-hook-sockets): Organics hook version (sails-hook-organics): Grunt hook version (sails-hook-grunt): Uploads hook version (sails-hook-uploads): DB adapter & version (e.g. sails-mysql@5.55.5): Skipper adapter & version (e.g. skipper-s3@5.55.5):


i am trying to add i18n in a sails app in the sails js docs the given examples are using i18n() or __() inside a ejs file but in the current project we are using handlebars and when trying to use __() its throwing error

{"level":"error","log":{"error":{"message":"Missing helper: \"__\"","name":"Error","stack":"Error: Missing helper: \"__\"\n    at Object.<anonymous> (node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)

my /config/i18n.js looks like this:

module.exports.i18n = {
  locales: ['en', 'ur'],
  defaultLocale: 'en',
  localesDirectory: 'config/locales'
};

my config/locales/en.json file looks like this:

{
    "signup": "Create Account"
}

and this how i am using it in my signup.hbs

<h4>{{{__ "signup"}}}</h4>
sailsbot commented 1 year ago

@iamaamir Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

iamaamir commented 1 year ago

also whem i am trying to access req.setLocale() or req.getLocale() i am getting error that such functions are not defined .