Translating URL patterns

Django supports translated strings in URL patterns. You can use a different translation for each language for a single URL pattern. You can mark URL patterns for translation the same way you would do with literals, using the ugettext_lazy() function.

Edit the main urls.py file of the myshop project and add translation strings to the regular expressions of the URL patterns for the cart, orders, payment, and coupons applications as follows:

from django.utils.translation import gettext_lazy as _urlpatterns = i18n_patterns( path(_('admin/'), admin.site.urls), path(_('cart/'), include('cart.urls', namespace='cart')), path(_('orders/'), include('orders.urls', namespace='orders')), path(_('payment/'), include('payment.urls', ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.