Django translation: can't find msguniq

為{幸葍}努か 提交于 2019-12-11 15:46:10

问题


I would like to do the translation inside Django application.

I was following the this tutorial but I run into problems.

After I run the code

python manage.py makemessages -l 'de'

I get the error

CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.

The weird thing is, that I have the gettext already installed

Warning: gettext 0.19.8.1 is already installed and up-to-date
To reinstall 0.19.8.1, run `brew reinstall gettext`

I have the settings set as:

# Translations
# Provide a lists of languages which your site supports.
LANGUAGES = (
    ('en', _('English')),
    ('de', _('German')),
)
# Set the default language for your site.
LANGUAGE_CODE = 'en'
# Tell Django where the project's translation files should be.
LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)
print(LOCALE_PATHS)

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

Do anyone know what could go wrong?


回答1:


Have you tried using django-admin:

django-admin makemessages -l de

Do you have in symlinked?

brew link gettext --force

Also, when I installed it on brew, there were a few extra steps. Did you do those?

  • I'm updating .zshrc, but if you use bash, it would be, say, .bashrc

If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/gettext/lib CPPFLAGS: -I/usr/local/opt/gettext/include export LDFLAGS=-L/usr/local/opt/gettext/lib export CPPFLAGS=-I/usr/local/opt/gettext/include




回答2:


Have you tried the command without the quotes around the language?

python manage.py makemessages -l de

django makemessages




回答3:


Check if you can run msguniq manually:

$ msguniq --help

If that gives you a command not found error, ensure that your PATH environment variable is set correctly for brew.



来源:https://stackoverflow.com/questions/50855974/django-translation-cant-find-msguniq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!