django i18n: Make sure you have GNU gettext tools

2020-05-31 09:49发布

I try django-admin.py makemessages -l zh_CN but has error :

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

after I use brew install gettext,it still get wrong.
Do I need to do something? here is my terminal screenshot
Please guide me thank you.

enter image description here

标签: python django
9条回答
该账号已被封号
2楼-- · 2020-05-31 10:12

Just below solution solved my problem. I am using Windows 10 64bit

1- Go to this link : https://mlocati.github.io/articles/gettext-iconv-windows.html

2- Download 32 or 64 bit shared and static windows installation files

3-Install both of files
4-Restart your computer

查看更多
再贱就再见
3楼-- · 2020-05-31 10:15

This procedure worked for me (OSX 10.11.2 - python v3.5 and Django 1.8) It should work with your configuration.

Install gettext GNU tools with Homebrew using Terminal

  1. Install Homebrew : /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Install GNU gettext : brew install gettext
  3. Create symlink : brew link gettext --force
查看更多
冷血范
4楼-- · 2020-05-31 10:15

Hi first of all make sure that your virtual environment is not in your root folder. I think it's better practice to keep your virtual environment outside of the root folder. Obviously make sure your environment is activated. Of course make sure you have gettext installed as well.

If your env folder is in your root folder

To test this just make sure you add {% load i18n %} in all your templates, choose a template and do something like this:

<h1>{% trans 'My Test to be translated' %}</h1>

Now run this command

django-admin makemessages -l 'zh_CN' -i your_venv

(Make sure you replace your_venv to the name of your virtual environment.

After you run the above command, you should get this in your terminal.

processing locale zh_CN

Now you should have a locale folder like this: locale/cn/LC_MESSAGES/django.po

Now you will need to compile the messages. Run this command

django-admin compilemessages

In your locale folder, now you should get you should see django.mo file as well, but you will notice the difference in django.po file. Just add your translation there, and you can test again by setting your en language to LANGUAGE_CODE = 'zh_CN' then just refresh and test the h1 string will be translated to Chinese.

In order for the above to work in your settings.py ensure you have this here, for now most important is the LOCALE_PATHS, but please check if this ('zh_CN', _('Chinese')), is correct

LANGUAGES = [
   ('zh_CN', _('Chinese')),
   ('en', _('English')),
]

LANGUAGE_CODE = 'en-us'


TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

In this reply, the most important part is to realize where your virtual environment is located. Reason why you get all these errors.

Please make sure you refer to this video here, it's a great tutorial. https://www.youtube.com/watch?v=xI97sLMd1rM

查看更多
登录 后发表回答