Oleg Tarasenko
Oleg Tarasenko

Reputation: 9610

django-sorting: Localization is not working

I am using django soring application:

https://github.com/directeur/django-sorting

I just wonder if there is a way to make local names for sorting filters... E.g. I am trying to localize following:

<th>{% anchor total Rating %}</th>

And using standard django trick

<th>{% anchor total _("Rating") %}</th>

is not helping... Don't know what to do...

Upvotes: 0

Views: 397

Answers (1)

BFil
BFil

Reputation: 13096

you should use the trans template tag from within templates..

https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#trans-template-tag

UPDATE

If you want the title to be translated, you'll just need to modify the anchor template tag code of django-sorting, for example, looking at the source here:

https://github.com/directeur/django-sorting/blob/master/django_sorting/templatetags/sorting_tags.py

Inside anchor you could modify it, for example, by adding the ugettext function as "_()" when the title is passed to the SortAnchorNode class:

return SortAnchorNode(bits[1].strip(), _(title.strip()))

Or you can choose another place to fire the translation, this is just for demonstration but it should work

that will translate the title you specify in your tag:

{% anchor total "Result" %}  //{% anchor field title %}

You need to be sure to have the words you'll pass translated in your dictionaries..

Upvotes: 1

Related Questions