Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, flask and creating a dual language app

I need to create a web app that can support dual languages namely English and Japanese. I don't need a translator, just a workflow for displaying text based on a user preference.

Is there such a framework where I don't have to reinvent the weel? Or do I have to create two separate sites?

like image 266
Tampa Avatar asked Aug 13 '12 15:08

Tampa


2 Answers

Multilingual websites are generally created using gettext (which is supported in many systems, including Django and also Flask). I have not used it personally but Flask-Babel appears to be the package that you need.

The basic idea is: you mark all English strings as translatable and you can then create translation files for other languages, such as Japanese. You can then load the strings from the appropriate language when a page is requested (in Django this is done automatically after some configuration, I can imagine it to be similar in Flask).

like image 123
Simeon Visser Avatar answered Oct 06 '22 09:10

Simeon Visser


Use python's gettext package for managing the multi language text and then set the language based on the 'Accept-Language' header or some URL parameter.

like image 41
buergi Avatar answered Oct 06 '22 10:10

buergi