Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use django-admin.py makemessages --all

Tags:

python

django

I am trying to create messagefile in my django project.

for this, i just wrote this into my home view function:

def startpage(request):
   # Translators: This message appears on the home page only
   output = _("Welcome to my site.")

and in settings.py

from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
   ('de', _('German')),
   ('en', _('English')),
   ('fr', _('French')),
   ('es', _('Spanish')),
   ('pt', _('Portuguese'))
]

and created locale directory inside my app.

now I am inside my app tree and giving this command:

django-admin.py makemessages --all

it is spitting out this

#!C:\workspace\newsportal\venv_np\Scripts\python.exe
# EASY-INSTALL-SCRIPT: 'django==1.6','django-admin.py'
__requires__ = 'django==1.6'
import pkg_resources
pkg_resources.run_script('django==1.6', 'django-admin.py')

and NOT creating messagefiles inside locale.

I tried with:

python manage.py makemessages --all

but it cannot find manage.py because i am inside my app, not in project tree. how is it done normally?

like image 312
doniyor Avatar asked Sep 08 '14 08:09

doniyor


1 Answers

You just need to add your locale directory paths to LOCALE_PATHS. For example:

LOCALE_PATHS = [
    os.path.join(BASE_DIR, "locale"),
    os.path.join(BASE_DIR, "yourapp/locale"), 
]

Once you have included some text to be translated in your project, just execute this command for each language you want to translate. In your case:

django-admin.py makemessages -l de
django-admin.py makemessages -l en
django-admin.py makemessages -l fr
django-admin.py makemessages -l es
django-admin.py makemessages -l pt

Then translate all the texts and compile them. I recommend to use django-rosetta for this purpose, which is a Django application that eases the translation process of your Django projects.

django-admin.py makemessages --all

Everything should work now

like image 82
cor Avatar answered Oct 05 '22 07:10

cor