django-sortable icon indicating copy to clipboard operation
django-sortable copied to clipboard

Translating sortable headers

Open mikecodona opened this issue 10 years ago • 1 comments

I'm hoping to be able to be able to translate the titles for a sortable link. I was hoping I'd get away with the below but as the title isn't treated as a Django variable it obviously doesn't work.

{% trans "Arrive" as arrive_text %}
{% sortable_link arrive arrive_text %}

The render method of the SortableLinkNode could be changed to something along these lines:

  def render(self, context):
    url, css_class = self.build_link(context)

    try:
        title_var = template.Variable(self.title)
        title = title_var.resolve(context)
    except template.VariableDoesNotExist:
        title = self.title

    return '<a href="%s" class="%s" title="%s">%s</a>' % (url, css_class, title, title)

Is that something that you'd consider accepting as a pull request? Alternatively, is there a better way of doing it that I've missed?

mikecodona avatar Sep 26 '14 17:09 mikecodona

I've prepared a PR for this, because we really needed to have it running in our project. See the PR here https://github.com/drewyeaton/django-sortable/pull/7

lnagel avatar Mar 24 '15 08:03 lnagel