Search code examples
djangogettext

manage.py makemessages doesn't work for project's urls.py file


I am running manage.py makemessages --ignore=venv/* -l fr which seems to be running correctly. Every gettext() call is present in the generated django.po files except the main urls.py file's, therefore showing only the English versions of the URLs.

Other urls.py files' (within apps) gettext() calls are successfully found and present in django.po files.

P.S.: I am aware of the fact that gettext does not support Python's new f-strings, however there is no f-string inside any gettext() call.

My main urls.py file looks like this:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import gettext_lazy as _

urlpatterns = i18n_patterns(
    path(f'{_("admin")}/', admin.site.urls),
    path(f'{_("narratives")}/', include('notebook.urls', namespace='narrative')),
    prefix_default_language=False,
)

Solution

  • It was caused by the way the f-strings work. When I change path(f'{_("admin")}/', admin.site.urls)
    with
    path('%(link)s/'.format(link=_("admin")), admin.site.urls) it did work as expected.

    I don't know the f-strings in depth, so this is the best workaround I could come up with.