For translating custom strings (intervals, subscription names, etc...) we've implemented a wrapper function that uses i18nstrings if available.

The function looks like this:

/**   
 * Wrapper function for i18nstrings() if i18nstrings enabled.
 * 
 * @param $name
 *   Name of the string, like "send_interval:$key:name"
 * @param $string
 *   String in default language
 * @param $langcode
 *   Optional language code to translate to, if not current page language
 * @param $textgroup
 *   Text group name for the string. It defaults to 'notifications' for this module
 */   
function notifications_translate($name, $string, $langcode = NULL, $textgroup = 'notifications') {
  return function_exists('i18nstrings') ? i18nstrings($textgroup . ':' . $name, $string, $langcode) : $string;  
}

About the UI for translation, see: Translating user defined strings.

Comments

pwolanin’s picture

Would it not be more generic to write this as:

function notifications_tt($name, $string, $langcode = NULL, $update = FALSE) {
  if (function_exists('tt')) {
    return tt($name, $string, $langcode, $update);
  }
  else {
    return $string;
  }
}

or even:

function notifications_tt($name, $string, $langcode = NULL, $update = FALSE) {
  static $tt;
  if (!isset($tt)) {
    $tt = variable_get('i18n_tt', 'tt');
     if (!function_exists($tt)) {
       $tt = FALSE;
     }
  }
  if ($tt) {
    return $tt($name, $string, $langcode, $update);
  }
  else {
    return $string;
  }
}

---
Work: BioRAFT

Weka’s picture

Another option is using the String Overrides module. This module allows the admin to change the Subscribe/Unsubscribe links text.
For example, override of: "Posts of type @type" >> "New @types" will change the original link text from: "Subscribe to: Posts of type Event" to: "Subscribe to: New Events".