Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

python - Is there a way to serve translations with flask-babel to react components

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...