Project

General

Profile

Drupal Knowledge for Developers

This is the Drupal knowledge base for CDM Data Portal developers.


Translations & Localization

Links

Drupal translations can be provided for individual modules and themes:

Contributed module/theme (called module from now on) interface translations are a bit more complex than core Drupal translations, because the translation template (POT) files are not generated automatically for you. Some developers generate translation templates for their modules, and put them into their module's translations directory. This is a nice gesture, but unfortunately these templates get outdated quickly. So it is advised that you generate fresh templates with the translation template extractor when you start translating. Translations of modules should be placed, along with the POT file, in the 'translations' subdirectory of the module. If you are not the module maintainer and you have created a translation, submit an issue against that module and attach your module files so the maintainer can add them to the project. (from http://drupal.org/translators)

**Create POT files using the Translation template extractor

Using the locale module to replace terms

In the following a method to transform hard coded English (= default) terms into other English terms is described, this technique has been used to solve #1325:

  1. activate the locale module

  2. go to admin/settings/locale/language/add and add a "Custom Language" e.g.: Language code: en-trans , Language name in English: english with replacements

  3. enable en-trans and set it as default

Setup the translations - two alternatives

  • Go to "Manage Strings" admin/settings/locale/string/search and search the string to be replaced, and translate it.

  • import at admin/settings/locale/language/import a .po for the *Language code: en-trans which might have been disseminated with the theme in the subfolder translations/en-trans/*.po

This rather simple approach might lead to conflicts if the same string is used in differen places but with diffrent meaning. So it is nessecary to make strings in particualr terms uniquely identifieable. This becomes possible using the second parameter of the t() function in Drupal. If '%' is used as second parameter the string will be passed to the theme_placeholder() function which can be implemented by the cdmdataportal module in order to strip of a idendifier prefix from the string. This prefix should either contain information on the type of the string (whether it is a term from cdm, a field name from a metata object, etc) or on the position in the data portal (page path; x-path of the html element; css class like attribute? renderpath ?) or both. -> 'TO BE DISCUSSED. If there is a translation for the string with prefix whole string would be replaced by the translation process. If there is not translation the prefix will be stripped of by the placeholder function.

here is an example in code snippets

$out = t('{term}Author', '%'); 

// the prefix "{term}" will be stripped of in cdm_dataportal_placeholder()
// if the whole string has not been replace by the translation applied 
// by the localization module

function cdm_dataportal_placeholder($text) {
    $pos1 = strpos($text, '{');
    $pos2 = strpos($text, '}', $pos1 + 1);
    if($pos1 == 0 && $pos2 > $pos1 + 1 ){
        $text = substr($text, $pos2);
    }
  return '<em>'. check_plain($text) .'</em>';
}

Add picture from clipboard (Maximum size: 40 MB)