How to override the django admin translation

0 votes

I'm trying to override the default translations of Django's admin site.

I'm using Django 1.6. My settings.py contains:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# ...

LANGUAGE_CODE = 'nl'
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)

I have copied the file django/contrib/admin/locale/nl/LC_MESSAGES/django.po to my_project/locale/nl/LC_MESSAGES/django.po and I've made some changes to it.

Next, I have run python manage.py compilemessages and python manage.py runserver.

When I visit localhost:8000/admin, however, I'm still seeing Django's default admin translations. What am I doing wrong?

Jun 12, 2020 in Python by kartik
• 37,510 points
2,224 views

1 answer to this question.

0 votes

Hello @kartik,

Just as you can override a Django-provided admin template by duplicating the template's name and directory structure within our own project, you can override Django-provided admin translations by duplicating a .po file's name and directory structure within our project.

Django's admin translations live in django/contrib/admin/locale/ and are organized by language in directories named [language code]/LC_MESSAGES/. These individual language directories contain two .po files, django.po and djangojs.po, and their respective compiled .mo files. You will be overriding the .po files, and compiling our own .mo files.

The first thing you have to do is enable translations in settings, and tell Django where you store our translation files.

settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# ...

LANGUAGE_CODE = 'nl-NL'
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)  

Hope this works!!

Thanks!!

answered Jun 12, 2020 by Niroj
• 82,880 points

Related Questions In Python

0 votes
1 answer

How can I disable the Django Celery admin modules?

Hello @kartik, To be more specific, in admin.py of any ...READ MORE

answered Jun 12, 2020 in Python by Niroj
• 82,880 points
1,280 views
0 votes
0 answers
0 votes
1 answer

How to execute a Python script from the Django shell?

Hello @kartik, The << part is wrong, use < instead: $ ./manage.py shell ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
9,826 views
0 votes
1 answer

How to get the SQL from a Django QuerySet?

Hello @kartik, Try this in your queryset: print my_queryset.query For ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,880 points
7,701 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,070 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,491 views
0 votes
1 answer

How do I add a link from the Django admin page of one object to the admin page of a related object?

Hello @kartik, Set show_change_link to True (False by default) in your inline ...READ MORE

answered Jun 12, 2020 in Python by Niroj
• 82,880 points
9,954 views
0 votes
1 answer

How to load a custom JS file in Django admin home?

Hello @kartik, You can override templates/admin/index.html and add the JavaScript ...READ MORE

answered May 14, 2020 in Python by Niroj
• 82,880 points
7,312 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP