Automatically redirecting to language URL

55 views
Skip to first unread message

Jonas Haag

unread,
Oct 26, 2017, 10:31:33 AM10/26/17
to django-d...@googlegroups.com
Hi!

Scenario: You have translated URLs, e.g. /pricing and /preise (German). Someone visiting your page in one language copies a page’s URL (e.g. /preise) and sends it to their friend, who uses a different language. The friend will get a 404 because their language’s URL translation (e.g. /pricing) doesn’t match the shared URL.

Possible solution: Find the URL translation in the friend’s language and redirect them to that page.

I’ve come up with a quick and dirty implementation of a Django middleware that finds the URL using brute-force: https://gist.github.com/jonashaag/e37b72f2270cb4038a808fbdbac6a1b9

Question 1: Is there a smarter way to find the correct URL?

Question 2: Do think this could be useful in Django proper? It could easily live in a third-party module as well.

Jonas
Reply all
Reply to author
Forward
0 new messages