42
For Mac users, after installing Homebrew and gettext as @Louis Barranqueiro says (steps 1 and 2):
- Install Homebrew :
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 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.
- [Django]-How Can I Disable Authentication in Django REST Framework
- [Django]-Access Django model's fields using a string instead of dot syntax?
- [Django]-What is the difference render() and redirect() in Django?
13
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
- Install Homebrew :
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install GNU gettext :
brew install gettext
- Create symlink :
brew link gettext --force
- [Django]-How to call function that takes an argument in a Django template?
- [Django]-How does the order of mixins affect the derived class?
- [Django]-Django "Cannot add or update a child row: a foreign key constraint fails"
10
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.
- [Django]-How can I change the modelform label and give it a custom name
- [Django]-Remove and ignore all files that have an extension from a git repository
- [Django]-Altering one query parameter in a url (Django)
4
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
- [Django]-Manually logging in a user without password
- [Django]-Django. A good tutorial for Class Based Views
- [Django]-Django model one foreign key to many tables
3
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
- [Django]-(fields.E300) Field defines a relation with model which is either not installed, or is abstract
- [Django]-History of Django's popularity
- [Django]-How can I call a custom Django manage.py command directly from a test driver?
2
@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
GETTEXT_PATH="/usr/local/Cellar/gettext/0.19.8.1/bin"
stores gettext_path in a shell variable —adapt the version number according to whatbrew install gettext
FILE="venv/bin/activate"
stores the path to the venv shell scriptecho "" >> $FILE
adds an empty line at the end of the to make sure the next command is on its own lineecho "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.source venv/bin/activate
runs the venv shell script so that variables are properly set. You can run this command more than once.
- [Django]-Exclude fields in Django admin for users other than superuser
- [Django]-How to get an ImageField URL within a template?
- [Django]-Django: change the value of a field for all objects in a queryset
2
If you’re using Docker just simply run below command:
apt-get update
Then:
apt-get install gettext
- [Django]-How to use django-debug-toolbar on AJAX calls?
- [Django]-How to return custom JSON in Django REST Framework
- [Django]-Why there are two process when i run python manage.py runserver
1
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 :
A universal variable is a variable whose value is shared across all
instances of fish, now and in the future – even after a reboot. You
can make a variable universal withset -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.
- [Django]-How to change Django Admin Custom list field label?
- [Django]-HTML – How to do a Confirmation popup to a Submit button and then send the request?
- [Django]-Django: show a ManyToManyField in a template?
1
that works for windows users.
i am using django 2
2 download the static version for your system
-
after downloaded execute the setup.
-
restart your pc and it will work.
That is all. THANKS.!!!!
- [Django]-Collectstatic error while deploying Django app to Heroku
- [Django]-User Authentication in Django Rest Framework + Angular.js web app
- [Django]-Django Admin app or roll my own?
0
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
- [Django]-Aggregate (and other annotated) fields in Django Rest Framework serializers
- [Django]-How to add url parameters to Django template url tag?
- [Django]-Django-debug-toolbar not showing up