Totty.js
Totty.js

Reputation: 15831

django internalization in urls? how to make urls like this: "en/articles" and "pt/artigos"...?

Hy!

I would need to make urls based on language.

Example:

If I had the language english and subcategory named "articles" then the url might be like this:

/en/articles/...

If the language were portuguese and subcategory already translated is "artigos" then the url will be:

/pt/artigos/...

How can I do it? I must use the urls.py or some monkeypatches?

thanks

Upvotes: 1

Views: 144

Answers (3)

armonge
armonge

Reputation: 3138

I've been using transurlvania with great success, it does exactly what you need and more, however i see that in the next Django release django-i18nurls will be included in django core so perhaps it would be better to learn that

Upvotes: 1

Thibault J
Thibault J

Reputation: 4446

This features is already existing in the yet-to-be released version 1.4. You can read about it in the release note.

If your really need this feature, and no existing app feets your needs, you can still try to apply the corresponding patch yourself.

Upvotes: 1

jro
jro

Reputation: 9474

Django LocaleURL is a piece of middleware that does exactly this. The documentation can be found in the source, or online.

Edit: I read over the fact that you want to translate the url itself... I'm not aware of any piece of code that provides this. Perhaps you could extend the LocalURL middleware to take care of the translations for you. Say you have a regex match like (?P<articles>\w+), you could in the middleware determine which view you want to use. Something like the following mapping perhaps?

if article_slug in ['articles', 'artigos', 'article']:
    article(request) # Call the article view

Upvotes: 1

Related Questions