7

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?

Peterino
  • 15,097
  • 3
  • 28
  • 29
doniyor
  • 36,596
  • 57
  • 175
  • 260
  • Have you set the locale path location in settings? `LOCALE_PATHS = ( os.path.join(BASE_DIR, "locale"), )` – cor Sep 08 '14 at 08:49
  • i created already ``locale`` dir inside my app and i am commanding from there, it should directly find it actually, shouldnot it? @cor – doniyor Sep 08 '14 at 08:50
  • I dont't think so... I would try that – cor Sep 08 '14 at 08:52
  • @cor i would want to have different translations for each app, so do i have to give all paths inside ``LOCALE_PATHS`` then? it doesnot make much sense to me :( – doniyor Sep 08 '14 at 08:54
  • No, just the locale folder path. I also recommend you installinig django-rosetta. – cor Sep 08 '14 at 08:55
  • i just want to create messagefile just for this app only, not project-wide. is it possible? @cor – doniyor Sep 08 '14 at 08:58
  • Yes, but you need to append its path to `LOCALE_PATHS`. For example: `LOCALE_PATHS = ( os.path.join(BASE_DIR, "locale"),os.path.join(BASE_DIR, "yourapp/locale"), )` – cor Sep 08 '14 at 09:03
  • 1
    @cor oh ok. thanks man. now it seems to be working. i just need the gettext tool for windows. heading for it;) – doniyor Sep 08 '14 at 09:06

1 Answers1

18

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

Peterino
  • 15,097
  • 3
  • 28
  • 29
cor
  • 3,323
  • 25
  • 46