Tutorials and snippets

Last updated on
7 September 2016

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Here are some multilingual advanced techniques which can be used for specific use cases. Please make sure to read the main sections of the "Multilingual Guide" handbook before trying these user-created snippets and tutorials.

For your information, complementary snippets are available at HowTos, tutorials and links if you are building your website with the contributed Internationalization (i18n) module in Drupal 7.

External references

Installing Drupal 6 in Another Language by Addison Berry (Lullabot)

One of Drupal 6's nice new features allows you to install Drupal using a language other than English. This video will show you how to get a translation, extract it and run the installer with the new language.

Watch the video (18 minutes, 28.7 MB in mp4 format)

Installing Drupal in French by Mickael, birdmanx35 (Lullabot)

Created for a GHOP task, this screencast details Drupal 6's new language support options, including installation and translation. This video actually has its own page in the handbook: http://drupal.org/node/212321

Watch the Video (9 minutes, .mov format, blip.tv)

How to Translate the Interface and Content of Drupal by Gabor Hojtsy (Acquia, Inc.)

Introduction to the Drupal 6 multilanguage features starting off from core features to contributed modules. Presented at Do It With Drupal.

View Slides

New i18n and l10n features in Drupal 6 Part 1 & 2

Greg Knaddison (greggles) has come out with an excellent screencast further demonstrating the powers of Drupal 6's language support, and the above module.

Watch the videos (approximately 30 minutes)

Create a customized language set to replace Drupal terminology

  1. Enable the locale module on the Administer > Modules page
  • Administer > Access control
  • Give yourself (and any other roles that should have it) permission to access locale
  • Go to the Administer > Localization page.
  • Select the add language tab.
  • Assuming English, create a custom language by adding en-US in the Language code text field.
  • Give your language a name, such as custom-English (be sure not to use spaces in your language name), and add the language.
  • This will return you to the main localization page. Set your new language as enabled and as the default.
  • Save the configuration.
  • Then disable the original English language set (that is, unless you would like users to be given the option to choose between the two in their account area).

Now, any time you visit a page with Drupal hard-coded content, it will be added into your language set database.

Once you have visited a page that you wish to change the content:

  1. Go to the manage strings page http://example.com/admin/locale/string/search of the localization section.
  2. Enter in the string you wish to search for.
  3. Edit the result and enter your replacement text.

Hide the active language from the language switcher block

The language switcher block does not support the ability to hide the active language, therefore this has to be done in template.php
This will also disable any active language links that use the theme_links

Edit your template.php file, this will usually be located in the folder for the theme you are using. If it does not exist, you can make it.

We will now want to copy the original theme_links code in to an override function called phptemplate_links
Located here http://api.drupal.org/api/function/theme_links/6

The modification that needs to be done is to unset the array element that contains the currently active language.
unset($links[$language->language])

The final function should look like this:


function phptemplate_links($links, $attributes = array('class' => 'links')) { global $language; $output = ''; if (count($links) > 0) { $output = '
  • '; //Removes the current active language from the language switcher unset($links[$language->language]); $num_links = count($links); $i = 1; foreach ($links as $key => $link) { $class = $key; // Add first, last and active classes to the list of links to help out themers. if ($i == 1) { $class .= ' first'; } if ($i == $num_links) { $class .= ' last'; } if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '' && drupal_is_front_page())) && (empty($link['language']) || $link['language']->language == $language->language)) { $class .= ' active'; } $output .= '
    • $class)) .'>'; if (isset($link['href'])) { // Pass in $link as $options, they share the same keys. $output .= l($link['title'], $link['href'], $link); } else if (!empty($link['title'])) { // Some links are actually not links, but we wrap these in for adding title and class attributes if (empty($link['html'])) { $link['title'] = check_plain($link['title']); } $span_attributes = ''; if (isset($link['attributes'])) { $span_attributes = drupal_attributes($link['attributes']); } $output .= ''. $link['title'] .''; } $i++; $output .= "
    • \n"; } $output .= '

    '; } return $output; }

    This function can be placed anywhere in the template.php file

Help improve this page

Page status: No known problems

You can: