开发者

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

Django makemessage coul开发者_Python百科d 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.


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.


I have written a new module for the purpose called tornado-babel which includes an extractor for babel to extract translatable strings from tornado templates. It will not create the CSV file for you, but the standard pot files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜