Compact language switcher

There is a snippet that can be used for language switching instead of the standard language switching block (see an example of page template code appended) - the point is (1) being more compact (e.g. you can insert the switcher into the page header next to the site name, slogan, or search box), and (2) hiding the current language. See #242646: Do not show a link to the current language D6

<?php

// this is copy&paste from locale_block in locale.module
$languages = language_list('enabled');
$links = array();
foreach ($languages[1] as $language) {
if ($language->language != $current) {
$links[$language->language] = array(
'href' => $_GET['q'],
'title' => $language->native,
'language' => $language,
'attributes' => array('class' => 'language-link'),
);
}
}

// this adds the real paths, i.e. if we are on a german page,
// the british flag will point to en/english_alias instead of
// en/node_with_german_content
translation_translation_link_alter($links, $_GET['q']);

// This one adds extended languages, i.e. those that are not enabled.
// Disable if you want only flags for enabled languages.
i18n_translation_link_alter($links, $_GET['q']);

// now add or replace text links by flags, according to your i18n settings.
if (function_exists('languageicons_translation_link_alter'))

Theming and PHP Snippets

The following section contains theming and PHP code snippets for interacting with the i18n and translation.module APIs, for Drupal 6. Most of them can also be used inside blocks, using PHP blocks.

Upgrade Internationalization from Drupal 5 to Drupal 6

The Internationalization (i18n) package provides full upgrade scripts for a smooth transition from Drupal 5 to Drupal 6. However, due to some multilingual features provided now by Drupal core and that the Internationalization package has been fully reworked, there are some special considerations. So, please, read this page before doing anything.

Drupal 6 upgrade notes

  • To upgrade from 5.x, first upgrade to the latest 5.x stable release. To upgrade from 4.x, first upgrade to 5.x, then to 6.x.
  • Note that some old features and behaviors have been dropped and replaced by new Drupal 6 multilingual features. This module won't pretend to replace Drupal core available features but to build on them and provide extended ones.
  • While the upgrade scripts already work for nodes and taxonomy, there's other data that is simply deleted by the main Drupal 6 core upgrade, like the menu items language.
  • Other parts like the multilingual block system have been completely reworked and will need manual reconfiguration. Existing normal blocks won't be lost but the language settings will need manual reconfiguration.

Translating user defined strings

The String Translation module (i18nstrings.module, part of the i18n project) allows translation of user-defined strings. This is an API module (that is, it doesn't do anything by itself) that must be enabled only when required by other modules in the i18n package.

Module developers: See how this can be used in other modules without introducing new dependencies: Notifications.

The string translation UI is integrated into the localization system. All strings will be translatable through the Administer > Site building > Translate interface

You must decide on the site default language before using this feature. Changing it later will garble all your user defined strings translations. Read below!

About Drupal Strings

The Drupal localization system allows translation of hardcoded strings, using locale module and .po files. However, user-defined strings (menu items, taxonomy terms, field names, etc.) are not translatable using Drupal 6 core. This is why the Internationalization package includes its own string translation layer, which keeps track and allows translation of most user-defined strings.

String Translation

Menus and primary / secondary links

With Drupal 6 core alone, user-defined menu items are not translatable. The Menu translation (i18nmenu) module, part of the Internationalization (i18n) package, provides the following features:

  • Allows setting a language when creating a custom menu item so that the menu item will only show up for that language.
  • Localizes other custom menu items without language. It does this by adding a "Limit search to: Menu" option on the Search tab of the Translate interface at Administer > Site building > Translate interface.

A menu item linked to a node, due to how the menu system works and the 'Language selection' feature in the Internationalization module, will be displayed only when the node language matches the page language. The Menu translation module relies on theming and blocks for displaying the right links for each case. Thus for uses different than displaying the menu in a block, it may not always work.

About primary / secondary links

This is a special case, as they're basically menus that can be displayed as a block but aren't always. Most of the themes display them directly instead of using a block so, for this case, the Internationalization module's multilingual menu items features won't work.

Multilingual variables (Drupal 6)

For Drupal 7, see the Variable Translation module documentation.

Some text and settings are stored in Drupal as variables, and some site-wide ones like 'site name' and 'site slogan,' along with module-specific ones, can be edited through the administration pages. The Internationalization package makes it so these variables can be translatable.

To enable these variables to be translatable we need to identify the low-level names Drupal uses for them. This can be done looking at the 'variable' table in the database or searching through the code. However, we'll show you how to translate the more common settings below.

Once you have identified the variables you want to be translated, they need to be added in the settings.php file for the site as follows:

/**
* Multilingual settings
*
* This is a collection of variables that can be set up for each language when
* internationalization (i18n) is enabled. These are the basic ones for Drupal
* core, but you can add your own here.
*/
$conf['i18n_variables'] = array(
// Site name, slogan, mission, etc..
'site_name',
'site_slogan',
'site_mission',
'site_footer',
'anonymous',
// Different front page for each language
'site_frontpage',
// Primary and secondary links
'menu_primary_links_source',
'menu_secondary_links_source',
// Contact form information

Pages

Subscribe with RSS Subscribe to RSS - i18n