HowTos, tutorials and links

Some external links and articles about Drupal 7 and i18n:

Configure Pathauto to work with language-specific path aliases

To configure Pathauto to have language-specific path aliases, do the following:

  1. admin/build/modules: enable Locale and Content Translation modules
  2. admin/build/block: enable the language switcher block (this is required since your path aliases will only show in the currently active language, the rest will show as unaliased)
  3. admin/settings/language/add: add a couple of new languages - say French and Spanish
  4. admin/settings/language/configure: change the 'Language negotiation' setting to 'Path prefix with language fallback'
  5. admin/content/types: edit the content types that require translation and set the 'Multilingual support' setting to 'Enabled, with translation' - the setting is in the 'Workflow settings' fieldset
  6. admin/build/path/pathauto: add new, language-specific patterns for the node types, say article/[title-raw] for French and artículo/[title-raw] for Spanish
  7. node/add/story: create a new item of content, and set the language to English (or whatever your default language is)
  8. node/NID/translate: click the Translate tab and then click the 'add translation' link for each language that you wish to have a translation

Taxonomy translation

The Taxonomy translation (i18n_taxonomy) module, part of the Internationalization (i18n) package, provides multiple options to translate taxonomy vocabularies and terms. For each vocabulary, you'll have to choose one of four different modes defining 'multilingual' behaviors for the vocabulary:

  1. No multilingual options for terms. Only the vocabulary will be translatable. (default) [previously called None]
  2. Localize. Terms are common for all languages, but their name and description may be localized. [previously called Localize terms]
  3. Translate. Different terms will be allowed for each language and they can be translated. [previously called Per language terms]
  4. Fixed Language. Terms will have a global language and they will only show up for pages in that language. [previously called Set language to vocabulary]

When a language is set for a vocabulary or term, only those that match the the current language will appear in taxonomy listings and when creating and editing nodes. If the language is set for a vocabulary, all the terms in that vocabulary will be automatically set to that language.

Translating user-defined strings

The String Translation module (i18n_string.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 Internationalization package.

Module developers: See how this can be used in other modules without introducing new dependencies: Using the i18n API.

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

Using the i18n API from other modules

If you want some of your module's strings and objects to be translatable using i18n API, there are some functions that need to be implemented.

Menu translation

Any module that displays a menu needs to provide a hook for i18n to be able to translate/localize it.

// If $tree is the menu tree to be displayed
if (function_exists('i18n_menu_localize_tree')) {
  $tree = i18n_menu_localize_tree($tree);
}

Multilingual variables

In order for your module's variables to be translatable they must be declared using Variable module hooks. If variables are declared using hook_variable_info() everything else will be handled automatically.

String translation

Internationalization module provides translation services for user-defined strings. It also tracks source strings and keeps them up-to-date using a 'string key' that is a string with these elements "textgroup:object_type:object_key:property_name".

Menu translation

With Drupal core alone, user-defined menu items are not translatable. The Menu translation module, part of the Internationalization (i18n) package, allows users to select a translation mode for each menu (Figure 1).

The following modes are available:

  • No Multilingual Options
  • Translate and Localize
  • Fixed Language


Figure 1

Translate and Localize Menus

For most use cases, and especially if the structure of your menus is consistent across languages, Translate and Localize is the preferred method of translating menus. You can create one menu for all languages, and translate or localize each menu item. There are two ways that menu items will be translated:

  • You can set a language when creating a custom menu item so that the menu item will only show up for that language (Figure 1). Menu items that link to nodes in a particular language will be treated this way.
  • You can localize other custom menu items without a language (for example, menu items linking to Views pages). Use the Translate tab to translate the menu item title and description (Figure 2). Translators can also use the 'Translate interface' pages to translate these menu items (Figure 3).

Pages

Subscribe with RSS Subscribe to RSS - i18n