Translate default language

The methods explained here work for both Drupal 6 and 7. When a difference exists it is outlined.

There're several reasons you might need to translate the default language, for example:

  • You need to change a few strings depending on the dialect spoken or because of personal preference.
  • You need to change the default language but it will probably break translations because they are based on default language.

Strings overrides in settings.php

This method is provided by drupal core and doesn't require any extra module (even locale.module).

String translation

The String translation module, part of the Internationalization (i18n) package, provides support for other modules to translate user-defined strings. It implements the i18n_strings function, which in Drupal 6 was commonly known as the tt function. The i18n_strings function is an API function that lets other modules (such as the Taxonomy translation and Menu translation submodules) manage translations of user-entered strings. Depending on which modules you have enabled that use this feature, different text groups will be available for translation.

In contrast to Drupal's standard localization system, which always translates from English, strings will be translated from the source language. By default the source language is the site's default language, so changing the default language could break these translations. You can set which language is used as the source language via Administration > Configuration > Regional and language > Multilingual settings > Strings.

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

Translating user-defined strings (module developers)

Old functions tt() and ts() have been deprecated. Use i18nstrings() and i18nstrings_update() instead.

The 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".

Some examples of these 'string keys' are:

taxonomy:term:12:name
nodetype:type:story:name

For translating these strings, the module must call this function before displaying them:

/**
 * Translate or update user defined string.
 * 
 * @param $name
 *   Textgroup and location glued with ':'.
 * @param $string
 *   String in default language. Default language may or may not be English.
 * @param $langcode
 *   Optional language code if different from current request language.
 * 
 * @return $string
 *   Translated string, $string if not found
 */
function i18nstrings($name, $string, $langcode = NULL) {
   .....
}

For strings that have an input format, you must use the function i18nstrings_text() that takes care of applying the correct filters if there is a translation.

/**
* Get filtered translation
*

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

Subscribe with RSS Subscribe to RSS - string translation