niwinz / django-jinja

Simple and nonobstructive jinja2 integration with Django.
http://niwinz.github.io/django-jinja/latest/
BSD 3-Clause "New" or "Revised" License
363 stars 102 forks source link

django.utils.translation.ugettext() is deprecated #293

Closed ShaheedHaque closed 2 years ago

ShaheedHaque commented 2 years ago

As of recent versions, django.utils.translation.ugettext() is deprecated. This results in warnings like this fragment:

.
.
.
templates/base_site.html.jinja:8: in block 'title'
    {% block title %}{{ _('paiyroll Administration') }}{% endblock %}
/usr/local/lib/python3.8/dist-packages/jinja2/ext.py:168: in _gettext_alias
    return __context.call(__context.resolve("gettext"), *args, **kwargs)
/usr/local/lib/python3.8/dist-packages/jinja2/ext.py:174: in gettext
    rv = __context.call(func, __string)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

message = 'paiyroll Administration'

    def ugettext(message):
        """
        A legacy compatibility wrapper for Unicode handling on Python 2.
        Alias of gettext() since Django 2.0.
        """
>       warnings.warn(
            'django.utils.translation.ugettext() is deprecated in favor of '
            'django.utils.translation.gettext().',
            RemovedInDjango40Warning, stacklevel=2,
        )
E       django.utils.deprecation.RemovedInDjango40Warning: django.utils.translation.ugettext() is deprecated in favor of django.utils.translation.gettext().

/usr/local/lib/python3.8/dist-packages/django/utils/translation/__init__.py:102: RemovedInDjango40Warning

I can see the code involved is in JInja2 itself, but was hoping there might be a way to deal with this here in the first instance?

wizpig64 commented 2 years ago

Like you said, this is really an issue with Jinja2's code.

Here's the commit from 2008 where they added the usage of ugettext: https://github.com/pallets/jinja/commit/3213355aef195818c282dabe51dfd5694c26d5f6#diff-b172bf04c4b9718c7c40ed89af39e268091b058c5fa97c788202175bf3185ef2

Luckily, it looks like their code is written in a way where Jinja only uses ugettext if the template engine provides it, but will otherwise happily use gettext. So the error should just go away once you upgrade to Django 4.