I am working in a team developing a web application utilizing python flask, front end is jinja2 with JS. Javascript is served through flask-assets and flask-babel is handling the translations of the project.
flask-babel is handling the translations without an issue for templates as well as served JS. Recently I was assigned with shifting a part of the applications to react. My current approach is to compile the relevant react part through webpack + babel and serve it through assets same way as the other JS. But flask-babel is just not servig translations to components converted in such a way.
I came up with several potential solutions to this problem:
- serve the translations with an API and fetch it when loading react components.
- utilize gettext-webpack-plugin which basically compiles react package for every language. The appropriate package should then be loaded.
- use react-intl package, which basically means convert pom to json, and serve it with react-intl inside the react. For now this solution is probably my favorite.
But this just seems wrong. If flask-babel is able to serve translations to javascript files via flask-assets, shouldnt it be able to do the same to react, which is basically also just JS? Or shouldnt there be a webpack plugin solving this issue? It seems to me like there is a very easy solution to this problem I am missing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…