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

I am trying to create a message file in my django project.

for this, I just wrote this in 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 a directory locale

inside my application.

now i am inside my application tree and give this command:

django-admin.py makemessages --all

      

he spits it out

#!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 DO NOT create message files inside locale

.

I tried:

python manage.py makemessages --all

      

but it can't find manage.py

it because I'm inside my application and not in the project tree. how is it done normally?

+3


source to share


1 answer


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 translation text in your project, simply run 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 using django-rosetta , which is a Django app to make it easier to translate your Django projects.

django-admin.py makemessages --all

      

Everything should work now

+8


source







All Articles