Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to generate tornado localization CSV file like django makemessage?

Django makemessage could generate i18n files, and make it more easier to translate.

As I see, tornado has support both CSV format and gettext format, but I can only use CSV version, because I will use it at appengine.

So, I am looking for a way to generate these CSV files for tornado base on scanning my codes and templates.

like image 963
guilin 桂林 Avatar asked Nov 05 '10 02:11

guilin 桂林


1 Answers

Ok, I think you a bit confused. You can use gettext and po/mo files from within appengine, since gettext is exported from Google's django.util implementation (a discussion of this can be found in the google-appengine google group) :

from django.utils.translation import gettext as _ 

I am not familiar with AppEngine CSV's i18n format, but there is a very easy way to extract internationalized strings from tornado's code and templates using xgettext, just basically force python from the command line. As an example:

 xgettext -L Python -o myproject.pot  *.html

That command will get all i18n'ed strings from *.html in your current directory and will place them on myproject.pot. You can initialize that file and translate into let's say ./it_IT/myproject.po using any commercial or opensource tool (I would recommend poedit or pootle) and once you have translated all strings you can convert the file into CVS using Translate Toolkit's po2csv, which is also written in python:

po2csv -i it_IT/myproject.po -o it_IT/myproject.csv 

The format is location:codeLine,source,target which is pretty simple end easy to convert to whichever other format you need (I am not familiar with appengine's i18n CSV format), you can call po2csv with no -o argument and pipe the output out from STDOUT.

I don't know if that solves your question, but basically I think you should adopt a code->pot/po->csv workflow since there are many tools that expect po/pot/mo and will allow you to handle your translations or work with translation memories/spellcheckers, etc.... try and let me know if you need any more help with that.

like image 136
EwS Avatar answered Sep 20 '22 11:09

EwS