0

I need to make an urlpattern different for each language, but following to the same view.

for example:

url(r'^category/(?P<slug>[\w-]+)/, 'news.views.category', name='category'), in english
url(r'^kategoria/(?P<slug>[\w-]+)/, 'news.views.category', name='category'), in polish

if you have EN set, "kategoria" won't work. Is it possible?

tunarob
  • 2,768
  • 4
  • 31
  • 48

2 Answers2

1

If you are using Django-version>=1.4. check internationalization for URL patterns. You can define translations for URLs using ugettext_lazy() or you can use i18n_patterns

machaku
  • 1,176
  • 8
  • 7
0

You should not create URL patterns like this .use i18n patterns in URL, in urls.py:

from django.translation import ugettext as _

Then make your URL patterns like this:

url(_(r'^category/(?P<slug>[\w-]+)/)) 

The translators will translate it.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Arhot
  • 1
  • 2
  • 2
    ​​​​​​​​​​​​​​​I don't know if my edit was correct or not, but please try to make your posts clear and awesome. For example that you should always use **4 spaces** to format long line/block of code. And \`code\` (backticks) to format a inline code. For more information, see [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting). You should check and correct these grammar and spelling mistakes before you post your post also, thanks. – Remi Guan May 17 '16 at 09:50