django i18n: Make sure you have GNU gettext tools

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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.

回答1:

For Mac users, after installing Homebrew and gettext as @Louis Barranqueiro says (steps 1 and 2):

  1. Install Homebrew : /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Install GNU gettext : brew install gettext

You shouldn't use brew link gettext --force in step 3, because it is risky (as Brew advises if you try). A better workaround is to set a new PATH variable for your virtual environment. So, in the postactivate file, which is located in the bin folder of your virtual environment folder, type:

export TEMP_PATH=$PATH export PATH=$PATH:/usr/local/Cellar/gettext/0.19.7/bin 

Note that you have to replace 0.19.7 by the version that is installed in your machine.

And in your predeactivate file, which is located in the same folder of postactivate file, type:

export PATH=$TEMP_PATH unset TEMP_PATH 

Now you can use the python manage.py makemessages -l <desired_language> without worries. :)

Cheers.



回答2:

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


回答3:

In Ubuntu:

$ sudo apt-get install gettext 


回答4:

This solution worked for me ( win. 7, 8 and 10 )

You need to download two folders:

  • gettext-runtime_0.18.1.1-2_win32
  • gettext-tools-dev_0.18.1.1-2_win32

You can find them here.

  • After you download them, unzip them and add the directory of the bin file of the both folders to the system variables PATH of your pc.

  • You will also need a file named libstdc++-6.dll download it from here and place it in your system directory. You will find adequate details on system directory here.

And that’s it. Hope it is useful for you.



回答5:

If you use fish shell, another way around is to add this path to $fish_user_paths.This variable is prepended to $PATH, so you don't have to set it in all your projects.

You can do it with the following command line :

set -U fish_user_paths /usr/local/Cellar/gettext/0.19.8.1/bin $fish_user_paths 

Remember to replace 0.19.8.1 with your gettext version.

This sets $fish_user_paths as a Universal Variable. Here's what help says about Universal Variables :

set -U

So setting this variable in your shell once (no need to do it in a config file) will save it even after logging out or rebooting.



回答6:

@max-malysh's answer solved it for me ―without touching system files.

Copy and run each of the following:

brew install gettext GETTEXT_PATH="/usr/local/Cellar/gettext/0.19.8.1/bin" FILE="venv/bin/activate" echo "" >> $FILE echo "export PATH=\$PATH:$GETTEXT_PATH" >> $FILE source venv/bin/activate 
  1. GETTEXT_PATH="/usr/local/Cellar/gettext/0.19.8.1/bin" stores gettext_path in a shell variable ―adapt the version number according to what brew install gettext
  2. FILE="venv/bin/activate" stores the path to the venv shell script
  3. echo "" >> $FILE adds an empty line at the end of the to make sure the next command is on its own line
  4. echo "export PATH=\$PATH:$GETTEXT_PATH" >> $FILE adds a command to the venv shell script; this command adds the path to gettext binaries to the global $PATH variable, so that they are used before OS binaries.
  5. source venv/bin/activate runs the venv shell script so that variables are properly set. You can run this command more than once.


回答7:

the problem is hinted in the output from brew...

it has installed the GNU gettext but hasn't linked it into your bin directory because OSX already provides a different version of gettext...

so Django doesn't know to run the version you installed from brew.

apparently brew is too cautious here though and you should just link it https://stackoverflow.com/a/9787791/202168



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