Translate Django group name

194 views Asked by At

I am creating a Django application where users will have different possible groups to manage their permissions.

I would like this application to be translatable in the future, but the group names are not translatable by default. How can I make this possible? I have thought about a few possible solutions, but I can't decide which one is best.

  • Replace the template where the groups are displayed and translate the group names.
  • Replace the group templates and change the __str__ method.

Can you think of another solution?

Which one do you think is the best?

1

There are 1 answers

0
Raida On BEST ANSWER

I finally decided to override the __str__ method of the Group model like that (in models.py)

from django.contrib.auth.models import Group
from django.utils.translation import gettext as _

Group.__str__ = lambda self : _(self.name)