Translatable Render Array

Categories

Component ID

2258907

Component name

Translatable Render Array

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

Module for creating translatable render arrays which are translated at the time of rendering. This makes it easier to write unit tests using simpletest because the use of the t() function makes it necessary to use the web tests due to call to the database layer. The translatable render arrays is a workaround to delay the call to the database layer and instead juggle a data structure.

The translatable render consists of 1 to 3 variables like the arguments of the t() function:

  • #translate: The string to translate.
  • #args: An associative array of replacements for variables handled by format_string().
  • #options: An assoctive array with possible keys 'langcode' and 'context'.
$render_array = array(
  '#translate' => 'Text to be translated with posibility of arguments like %escaped, @escapedformatted, !nosanitization',
  '#args' => array(
    '%escaped' => 'one <b>escaped</b> argument',
    '@escapedformatted' => 'an <em>emphasized</em> argument',
    '!nosanitization' => '<script>alert("Danger, Will Rogers")</script>',
  ),
  '#options' => array('context' => 'Optional context'),
);

Attribution

This module has been developed as utility module for migrating the website bibliotek.dk to Drupal 7 done by DBC a/s (the Danish Bibliographic Centre) who maintains and develops the website.