Translating custom strings (i18nstrings wrapper)
Last modified: October 20, 2009 - 10:59
For translating custom strings (intervals, subscription names, etc...) we've implemented a wrapper function that uses i18nstrings if available.
The function looks like this:
/**
* Translate user defined string. Wrapper function for tt() if i18nstrings enabled.
*
* @param $name
* Textgroup and location glued with ':'.
* @param $string
* String in default language. Default language may or may not be English.
* @param $langcode
* Optional language code if different from current request language.
* @param $update
* Whether to force update/create for the string.
*/
function notifications_tt($name, $string, $langcode = NULL, $update = FALSE) {
if (module_exists('18nstrings')) {
return tt($name, $string, $langcode, $update);
}
else {
return $string;
}
}About the UI for translation, see: Translating user defined strings.

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