Last updated March 16, 2012. Created by fago on March 12, 2012.
Edited by August1914. Log in to edit this page.

In order to make make an action or condition translatable via the provided Rules translation module you may denote textual parameters to be translatable. "Textual parameters" are parameters of type 'text', 'token' or 'list' or 'list'.

A parameter may be denoted as translatable just by setting the translatable key to TRUE. Then, the action will receive the translated value as argument.

<?php
/**
* Implements hook_rules_action_info() on behalf of the system module.
*/
function system_rules_action_info() {
  return array(
   
'drupal_message' => array(
     
'label' => t('Show a message on the site'),
     
'group' => t('System'),
     
'parameter' => array(
       
'message' => array(
         
'type' => 'text',
         
'label' => t('Message'),
         
'sanitize' => TRUE,
         
'translatable' => TRUE,
        ),
       
// Further parameters...
     
),
     
'base' => 'rules_action_drupal_message',
     
'access callback' => 'rules_system_integration_access',
    ));
}
/**
* Action: Show a drupal message.
*/
function rules_action_drupal_message($message, $status, $repeat) {
 
drupal_set_message(filter_xss_admin($message), $status, $repeat);
}
?>

That's it. Users may translate the message text via the Rules translation module and $message will be automatically translated.

By default the argument value will be always translated to the current interface language (global $language). If that's not suitable, it's possible to override that by defining a parameter named language. If this parameter exists, the argument value will be translated to the specified language. For example, the "Send mail" action makes use of that so that it is possible to select "user:preferred-language" as the target language:

<?php
/**
* Implements hook_rules_action_info() on behalf of the system module.
*/
function system_rules_action_info() {
  return array(
   
'mail' => array(
     
'label' => t('Send mail'),
     
'group' => t('System'),
     
'parameter' => array(
       
'to' => array(
         
'type' => 'text',
         
'label' => t('To'),
         
'description' => t('The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822.'),
        ),
       
'subject' => array(
         
'type' => 'text',
         
'label' => t('Subject'),
         
'description' => t("The mail's subject."),
         
'translatable' => TRUE,
        ),
       
'message' => array(
         
'type' => 'text',
         
'label' => t('Message'),
         
'description' => t("The mail's message body."),
         
'translatable' => TRUE,
        ),
       
'from' => array(
         
'type' => 'text',
         
'label' => t('From'),
         
'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
         
'optional' => TRUE,
        ),
       
'language' => array(
         
'type' => 'token',
         
'label' => t('Language'),
         
'description' => t('If specified, the language used for getting the mail message and subject.'),
         
'options list' => 'entity_metadata_language_list',
         
'optional' => TRUE,
         
'default value' => LANGUAGE_NONE,
         
'default mode' => 'selector',
        ),
      ),
     
'base' => 'rules_action_mail',
     
'access callback' => 'rules_system_integration_access',
    ));
/**
* Action Implementation: Send mail.
*/
function rules_action_mail($to, $subject, $message, $from = NULL, $langcode) {
 
// Send mail...
}
?>

As above $subject and $message will be passed in already translated.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.