Community Documentation

Translating custom strings (i18nstrings wrapper)

Last updated May 4, 2010. Created by Jose Reyero on October 20, 2009.
Log in to edit this page.

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

Would it not be more generic

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: Acquia

Changing Strings Alternative

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

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here