views:

43

answers:

1

Eclipse has a function called Externalise all Strings, which will move all strings to an properties file.

Is there such a solution available for Django/Python?

Basically I have a large project with number of views/models/templates, and going through all of them, and putting

string -> _("string") etc is a big pain, so is there a way to automate this?

+1  A: 

It is automated in Django and has been for a long time. But the docs are a bit hard to find ;)

You can use the makemessages management command, or if you run an older version of django run django/bin/make-messages.py.

Link to the docs: http://docs.djangoproject.com/en/dev/ref/django-admin/#makemessages

Example:

django-admin.py makemessages --locale=en
WoLpH
I am a bit confused. The documentation for this command says "Runs over the entire source tree of the current directory and pulls out all strings **marked for translation**." (emphasis mine). Doesn't it mean that you would have to _mark_ them yourself with `_()` first? Or am I getting it wrong?
Manoj Govindan
@Manoj Govindan: Yes, that's correct. You have to use the `_()` method to mark them as available for translation. And use `{% blocktrans %}` for templates.
WoLpH
@WoLpH: Got it. I believe that you are addressing a different problem than the OP. The OP wants to know how to _automatically replace_ all instances of plain strings with those wrapped with `_( )`. You are suggesting a way to pull out strings _already_ wrapped with `_( )`
Manoj Govindan
@Manoj Govindan: it seems that I have misunderstood the question. In that case I don't konw a "proper" solution. Although a couple of regular expressions might work, that would be a risky thing to do.
WoLpH
Yes, I want tings as Manoj suggests. Comon, someone must have had to do this in the past. :)
uswaretech
@uswaretech: well... I've been in the same situation once. And I simply used a regex to find all strings. Not foolproof but you have to replace it manually anyway.
WoLpH