Just got started with i18n for translating my website in Node. I'm at a bit of a loss of how to translate text that is generated after the DOM has loaded and jade file rendered (like after a user clicks a button).
I understand that i18n is a server side module and my new text generated is on the client side.
I'm also running express, if that helps.
What I want to do is to be able to translate text that has been generated by javascript on the client side. Consider an arbitrary button:
INDEX.JADE
form.feedback-r
a#submitclientiddd.button.button-primary #{i18n.__('Reply')}
// Other Jade Stuff Here
script(src='javascripts/clientside.js', type='text/javascript')
CLIENT SIDE JS
$("#posts").on("submit", "form.feedback-r", function(e) {
actbutton.html("Sending").addClass("feedback").removeClass('send_reply').prop("disabled", true);
});
... AJAX FUNCTION REQUEST AND ON SUCCESS ...
actbutton.html("Reply").addClass("success-text").prop("disabled", false);
SERVER SIDE JS
res.render('index', { title: 'Page Title', i18n: res});
- First button text rendered by jade through i18n with (i18n.__('Reply')) and translated properly
- User clicks on button
- Text is changed via jQuery to read "Sending", and after an AJAX request back to "Reply"
- The button text is no longer translated since it was dynamically generated
Is there a way to use i18n on the client side to solve this problem? In the most ideal case, I'd like to just do this on the client side, but it's not working:
actbutton.html(i18n.__('Reply'));