node-localize : Save and render html syntax and tags information in translation files

node-localize : Save and render html syntax and tags information in translation files

Problem

I’m using Node.js and ExpressJS with node-Localize (https://github.com/AGROSICA/node-localize) for a web site.

I have a web page that contains a biography splitted by multiples paragraphes (<p></p>).

Is there a way to save and render html syntax and tags information in my translation file ?

"Bio" : {
    "en-US" : "<p>A first paragraphe of information</p><p>And a second one</p>",
    "fr" : "<p>Un premier paragraphe d'information</p><p>Et un deuxième</p>"
}

/*And the html...*/
<%= translate("Bio")%>

Because I don’t want to use the following syntax

"BioParagraphe1" : {
    "en-US" : "A first paragraphe of information",
    "fr" : "Un premier paragraphe d'information"
},
"BioParagraphe2" : {
    "en-US" : "And a second one",
    "fr" : "Et un deuxième"
}

/*And the html...*/
<p>
    <%= translate("BioParagraphe1")%>
</p>
<p>
    <%= translate("BioParagraphe2")%>
</p>
Problem courtesy of: RPDeshaies

Solution

I found a solution, I was able to render my html content from a string using the following sintax

/*I'm using the "<%-" instead of the "<%=" */
<%- translate("BioParagraphe1")%>
Solution courtesy of: RPDeshaies

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *