在翻译 URL 模式之后,我可以使我的 url 以活动语言为前缀,但我无法翻译它们。
网址.py
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from exercises.views import ExerciseListView
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
urlpatterns += i18n_patterns(
...
url(_(r'^exercises/$'), ExerciseListView.as_view(), name='list'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
语言环境/es/LC_MESSAGES/django.po
#: myproject/urls.py:54
msgid "^exercises/$"
msgstr "^ejercicios/$"
管理.py 外壳
>>> from django.core.urlresolvers import reverse
>>> from django.utils.translation import activate
>>> activate('en')
>>> reverse('list')
'/en/exercises/'
>>> activate('es')
>>> reverse('list')
'/es/exercises/' <---- should be /es/ejercicios as translated in .po
如何使reverse('list')显示'/es/ ejercicios /'?