Language negotiation implemented

Two posts back I was writing about my plans to implement language negotiation forĀ getgnulinux.org. I’m happy to announce that its implementation was completed today.

“Language negotiation is a function of the HTTP protocol which lets a server choose among several language versions of a page, based on the URL and on preference information sent by the browser (specifically in the Accept-Language header).” – http://www.w3.org/International/questions/qa-when-lang-neg

Before language negotiation was implemented, http://getgnulinux.org/ would always bring the visitor to the website in its default language (i.e. English). Now, when the language preferences are properly set in the visitor’s web browser and the website is available in one of the preferred languages, the website will automatically display the page in the visitor’s preferred language. It will only do this for languages for which the translation is complete (at the time of writing this, these are Hebrew and Asturian). This was a conscious design decision – it wouldn’t be very nice to display a page which is only partly translated.

Other changes came along with the implementation of language negotiation. The language menu on the top of each page now only shows the languages for which the translation is complete. Incomplete translations are still accessible from the “More languages” item in the language menu. This link brings the user to the new language selection page which gives an overview of all translations and their status.

The implementation of language negotiation was actually very simple. Language negotiation is a common feature for websites which means that there is a good chance that someone has already written freely available code for it. And indeed, someone has. There is HTTP::negotiateLanguage from PEAR, PHP’s own structured library of code. However, I used a modified version of that function which I got from Matthew Somerville’s website. The reason I chose Somerville’s version is because apparently PEAR’s version fails on one criterion (see Somerville’s page for details). This also allowed me to adapt some code to GGL’s code which made implementation even easier.

Leave a Reply

Your email address will not be published. Required fields are marked *