[Answered ]-Django – Change timeuntil language without changing application language

2👍

You have to create custom template filter which will call django’s timeuntil with different locale. For example italian version will look like this:

# app/templatetags/timeuntil_it.py
from django.template.base import Library
from django.template.defaultfilters import timeuntil_filter
from django.utils import translation

register = Library()

@register.filter
def timeuntil_it(value, arg=None):
    with translation.override('it'):
        time_until = timeuntil_filter(value, arg)
    return time_until

And in the template you should load this template library:

{% load timeuntil_it %}
{{ future_time|timeuntil_it }}

Leave a comment