Drupal 6: On Mouse Click Swap Block Contents

Problem:

A Drupal 6 website contains a left navigation bar that is in English. The site hosts an enormous epic poem (think the Illyiad) in a foreign language (Arabic). As more international visitors hit the site it would be nice if they could choice to see menu navigation in readable Arabic.

There is an Internationalization module for Drupal 6 and 7 but those modules assume page links are generated from translated content. We will not be translating every page on the site; the site offers audio clips in Arabic and also video in Arabic. We simply want to enable site visitors to be able to understand the main site navigation area and hopefully the sub-pages will be self-explanatory.

Proposed Solution:

The site currently requires Javascript. So we can assume users have JS. What we could likely try is the following steps:

We can attempt to create a JS enabled checkbox to toggle a variable to swap out the English main menu, with Arabic content.

We’ll have to remember this choice of the user for the duration of the users visit, so will likely have to use Cookies or Session values to do this.

Somehow we have to have store our Arabic menu somewhere in Drupal as well.

This solution is a general approach that is not necessarily Drupal specific, the same approach could work for nearly any framework or programming language.

Implementing Our Solution within Drupal

For organizational purposes we will create a custom module for a majority of our PHP code. We will also utilize a custom Drupal Theme to place some of our code primarily dealing with display logic closer to the theme layer.

In the Drupal menu system we create an Arabic menu simply pointing to our (currently) English content — but the menu items are in Arabic. Drupal will make this menu available as a Block of content:

All the above pieces of code allow us to have a small language selector that in this case overrides a typical Drupal block. If you have any questions regarding this post please feel free to inquire in the comments!

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com