Internationalised front page in Drupal

Note: The following applies specifically to Drupal 7. There are plenty of howtos on this subject to be found on Google, but many of them refer to older Drupal versions, and few are clear on what to do if you’re not already familiar with the concept of multilingual variables in the first place. This Stack Overflow thread finally made things clear to me.

I’ve finally switched our choir’s website to a bilingual version. Formerly, the entire site was in German only; now, links in the header allow visitors to switch between German and English. As Drupal keeps track of its nodes and knows which two nodes are different language variants of the same content, menu entries work consistently and switching the language while “in” the site takes you to the selected language version of the correct page, i.e. the same one you were on before the language switch, only now in your chosen language.

The front page was a bit tricky, though.

Drupal knows that the front page is the default page (i.e. the one it takes you to when you don’t have a specific node id or name in your URL – e.g. http://www.amerlingchor.at/ or http://www.amerlingchor.at/en/), and it sets its links accordingly. Even if you navigated directly to the front page node (with the node name in the URL, like so: http://www.amerlingchor.at/de/startseite), the language switcher block, when displayed on the front page, will link to the unspecific URL (http://www.amerlingchor.at/de/ and http://www.amerlingchor.at/en/). That’s fine, as long as Drupal knows how to handle the default front page depending on the selected language. But by default it doesn’t.

The default front page is configured on the /admin/config/system/site-information page, under “Default front page”. Note that the text field is prefixed by a base URL, and on a multilingual site, that includes a language selector, like so: http://www.amerlingchor.at/de.

To make this setting multilingual, you need the variable translation module. Once this is enabled, the variables section of the multilingual settings page (/admin/config/regional/i18n/variable) allows you to pick which system variables should have different values for different languages. “Default front page” enables multilingual values for the setting we’re interested in.

After activating this variable and going back to the site information page, Drupal informs you that the default front page is now indeed a multilingual variable:

Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed. This is a multilingual variable.

This means that the settings page can now be switched between languages, and in each case, the default front page for the selected language can be specified. To easily switch the languages, the page now includes a list of language links at the top, but those don’t seem to work. Instead, manually edited the URL to switch to your desired language, e.g. by changing http://www.amerlingchor.at/de/admin/config/system/site-information to http://www.amerlingchor.at/en/admin/config/system/site-information. You will see that the value of the default front page field changes depending on the language, as will the language in the base URL displayed in front of the field. Just configure the correct path for each language, and you’re set. The node paths can be anything you like, and the front pages in different languages don’t necessarily have to use the same name.

This entry was posted in Drupal and tagged , , . Bookmark the permalink.

Leave a Reply

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