1

I want to have a custom error page shown to the user in case of an error. My problem is, that it has to be i18n-ed.

Idea:

Validate in node -> if not accepted -> res.render('error', {message: errorMessageNameTooLong}); -> in jade, render that to a placeholder, which translates the errors from my translation.json p(data-i18n='errorMessageNameTooLong')

Problem:

How can i pass the message, so that the VALUE will be the data-i18n attribute in jade?

So far, i'm stuck with pre-formatting my jade template to p(data-i18n="errormsg") but that makes it impossible to display (i.e. translate) more than one error. I want the p to have a custom data-i18n attribute, depending on what error it actually is...

i hope that is understandable :D

thanks for the help :)

Community
  • 1
  • 1
user3787706
  • 659
  • 1
  • 6
  • 18
  • Possible duplicate of [Put Jade local variable in tag attribute](http://stackoverflow.com/questions/5081534/put-jade-local-variable-in-tag-attribute) – Francisco Presencia Oct 19 '15 at 22:27

2 Answers2

1

Your answer is one way, but there's an easier one:

p(data-i18n=errMsg)

Just put the variable after the = without the ""

Check out this question for an in-depth explanation or check the official documentation.

Community
  • 1
  • 1
Francisco Presencia
  • 8,732
  • 6
  • 46
  • 90
0

Ok i actually just found it out myself.. and it was absolutely straightforward.

solution:

router.post('/register'):

if(username.length > MAX_USERNAME_LENGTH) {
  res.render('error', {title: "error.error", errMsg: "error.nameTooLong"});
}

error.jade:

block content
  h1(data-i18n="#{title}")
  p(data-i18n="#{errMsg}")
Community
  • 1
  • 1
user3787706
  • 659
  • 1
  • 6
  • 18