I'm currently developing a music platform, using NodeJs, Express 4.0, and EJS as my template engine. As we must have a player constantly playing through our site navigation, as for SoundCloud, my site content is loaded dynamically with AJAX calls that get JSON data, and html is rendered client side with EJS client library.
For now, I send all my templates on first page load, and for each page request, I ask the server corresponding JSON data, and render it client side with EJS library.
I've been working on internationalisation for a few months, and as for now, depending on req.acceptsLanguages('fr', 'en')
, I serve one of my 2 sets of templates (that are in folders fr/ or en/) on initial page load, and my content is loaded client side afterwards as:
$.get(view, function (data) { // data is a simple JSON object
var html = ejs.render(templates.view, data); // Render with EJS client library
$wrapper.html(html); // Set new HTML
});
Though I have 2 sets of templates, and I have to change both views every time a template changes. It is a bit boring but mainly source of errors (and I have only 2 translations for now!). I ran into great 'i18n-node': https://github.com/mashpie/i18n-node that enables to have only one template that loads the right translation with seperate JSON files (en.json, fr.json). This module works well on first rendering, but of course as I don't have a client i18n support or client ejs that supports i18n, I can't render my templates client side afterwards (as well as for ejs or for i18n).
I checked but found nothing about a good client i18n library that would load the locale.json file at the beginning, and render templates accordingly along with ejs client side, do you know one ? I've seen similar ways on Angular and React but I am not using those.
Or maybe am i just thinking the wrong way? I also thought of rendering templates server side and send HTML directly, but I've read that sending only valuable and light JSON data, then render it client side is better than sending full HTML in terms of performance, especially for mobile, and I would love to keep it like that.
Any thoughts or sources ?