Multilingual pretty URLs

August 3, 2006 by Oliver
Filed under: Computers, Languages, Programming, Technology, Web Programming 

There is more and more emphasis on pretty URLs these days. With things like Ruby on Rails around to easily support it and better knowledge and use of things like mod_rewrite the days of horrible query strings is going away (excluding of course the most used websites – search engines). But how do you make your multilingual website have pretty URLs?

My language learning app uses the Zend Framework and so uses pretty URLs by default. I need the interface available in many languages, but then the URLs should be pretty in a localized way.

For example, starting a new Finnish lesson uses the following:

/lesson/new/fi

That would be the new action of the lesson controller with an extra language code parameter of fi.

In German this should be something like:

/lektion/neu/fi

By default this would access the neu action of the lektion controller.

The “simple” solution would be to write lots of controllers that just delegate to the real one. Which is silly. Instead an extra layer has to be added to the routing process some sort of look-up table mapping localized URL fragments with “real” canonical ones. This should be fairly simple with Zend Framework (although I haven’t actually tried yet).

Just an important issue no-one seems to have brought up yet…

pretty URLs, Zend, Zend Framework, web frameworks, MVC

Comments

2 Comments on Multilingual pretty URLs

  1. RyanC on Thu, 3rd Aug 2006 10:19 pm
  2. How would you do multiple parameters in the URL?

    I don’t really mind query strings in URLs, it may look neater, but its not a big deal if the URLs a bit long is it?

  3. Oliver on Fri, 4th Aug 2006 8:16 am
  4. With Zend Framework (and Ruby on Rails) you set up “routes” which define possible URLs and the parameters they represent. The default route is:

    “:controller/:action”

    I also have:

    “lesson/:action/:language”

    You can still use query string parameters as well for complicated things – although most complicated things are submitted using a form and you’re better off using POST anyway.

    There are a couple of advantages besides looking prettier. Firstly it’s theoretically possible for someone to type the URLs to a page they want to get to straight away* and search engines treat them better.

    * It still does security checks as before. If you go straight to /lesson/new/fi without logging in it redirects you to the log in page.