broinjc broinjc - 1 month ago 28
Python Question

django-admin.py makemessages not working

I am trying to translate a string.

{% load i18n %}
{% trans "Well, Hello there, how are you?" %}


to...

Hola amigo, ¿que tal?


My settings.py file has this:

LOCALE_PATHS = (
os.path.join(BASE_DIR, 'translations'),
)


And I am getting this:

(env)glitch:translations nathann$ django-admin.py compilemessages
CommandError: Can't find msgfmt. Make sure you have GNU gettext tools 0.15 or newer installed.


I also don't understand this error message.

(env)glitch:ipals nathann$ django-admin.py makemessages -l es
CommandError:
This script should be run from the Django Git tree or your project or
app tree. If you did indeed run it from the Git checkout or your project
or application, maybe you are just missing the conf / locale(in the
django tree) or locale(for project and application) directory? It is not
created automatically, you have to create it by hand if you want to
enable i18n for your project or application.


The docs: https://docs.djangoproject.com/en/1.6/ref/django-admin/#django-admin-makemessages

And for bonus upvotes, a related question:
gettext wasn't linked when I installed it... Any help with this one? Should I force it?

glitch:translations nathann$ brew link gettext
Warning: gettext is keg-only and must be linked with --force
Note that doing so can interfere with building software.


Thanks!




UPDATES:

I have since changed the name of translations to locale and updated my settings.py accordingly. then I ran this again and it's still complaining about gettext:

(env)glitch:ipals nathann$ mv translations/ locale
(env)glitch:ipals nathann$ django-admin.py makemessages -l es
CommandError: Can't find xgettext. Make sure you have GNU gettext tools 0.15 or newer installed.


I also found this:

Understand homebrew and keg-only dependencies

after reading this:

(env)glitch:ipals nathann$ brew install gettext
Warning: gettext-0.18.3.2 already installed
(env)glitch:ipals nathann$ brew link gettext
Warning: gettext is keg-only and must be linked with --force
Note that doing so can interfere with building software.

Answer

After making sure I had this in settings:

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)
print(LOCALE_PATHS)

I double checked I had the locale directory in the right place with its name spelled correctly.

I ended up linking gettext (after asking about that on superuser):

brew link gettext --force

manage.py compilemessages

django-admin.py makemessages -l es

And BAM. I've got my po file.

But the doctor says:

Warning: Some keg-only formula are linked into the Cellar.
Linking a keg-only formula, such as gettext, into the cellar with
`brew link <formula>` will cause other formulae to detect them during
the `./configure` step. This may cause problems when compiling those
other formulae.

Binaries provided by keg-only formulae may override system binaries
with other strange results.

You may wish to `brew unlink` these brews:

    gettext
Comments