Question

I'm planning to use Python Bottle framework for a simple website. Except for the numerics (eg., data shown in a table), all output has to be in Japanese. So instead of outputing "345.65 meters", I need to output "345.65 ".

Is there anyway I could create a text file containing (english) key = (japanese) value pairs ... something like:

meters = メートル  <-- love google translate 
seconds = ...
height = ....
Welcome = ... 
Error = ....

Then read this to a dictionary perhaps and translate my strings at run time: eg.,

settranslationfile("JapaneseWords.txt");
response.write( "<li"> + 345.65 + translate("meters") + "</li>" ).  

I do not know Japanese or how Unicode/localization stuff works. If I have to, I'll try to learn how Unicode works ... but what's the path of least resistance to achieving this. Any Python libs that do this? A file like "JapaneseWords.txt" can most likely be filled in by the Japanese client and sent to me.

If there are such facilities in other frameworks, I would be willing to consider a switch over to them - preferably Python based frameworks and then Java.

Was it helpful?

Solution

What you just described already exists and it is called gettext (edit: also see Python's gettext module). It does exactly that and I'm not sure if it the Bottle framework supports it but I do know that the Django framework (also Python) does support it.

It should certainly be possible to integrate it into your Bottle web application but if you're willing to switch then here is the Django documentation on internationalization and localization.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top