anthony-dandrea anthony-dandrea - 11 months ago 77
React JSX Question

How to handle python i18n translations with react

I'm looking into bringing React into my codebase(pyramid, jinja2). It almost looks like a good fit. I'm just confused as to how to handle translations from python. I'm using the

library and I would normally just have
function in context that translates strings like
to "Hola" and whatnot. If I moved to React my markup would now be in JS. And I don't want to have Jinja render my JS so it remains static. Is there a good way to handle this?

Answer Source

Ended up using and serving up the specific bundle file based on a saved language setting.

So on the backend we store in the database which language a user wants to use. We have json files of translations for all the languages & words we support. When compiling the bundle files with this plugin we get a bundle for each language that uses those json files to swap out the translated words. So something like bundle.en.js for english and for spanish. When a user requests a page we serve up the bundle file associated with their selected language stored in the DB.