public static function LocalizeFields::translate in Localize Fields 7
Translates a string taking possible translation context and possible encoding of single/double quotes into consideration.
Utility method, for non-standard form manipulation.
Check this module's help or settings page for context patterns, or use the ::context() method. The context argument should not be empty if this module is set to use context + no non-context fallback (check settings page).
$label = LocalizeFields::translate('whatever', array(), LocalizeFields::context('some_node_type', 'some_field_name', 'label'));
Parameters
string $source:
array $args: Ignored; args in field labels, description etc. aren't applicable (nor in core).
string $context:
Return value
string
File
- ./
LocalizeFields.inc, line 242 - Drupal Localize Fields module
Class
- LocalizeFields
- @file Drupal Localize Fields module
Code
public static function translate($source, $args = array(), $context = '') {
if (($localize = self::$localize) == -1) {
// Save a method call if possible.
$localize = self::localize();
}
if (!$localize || !$source || ctype_digit('' . $source)) {
return '' . $source;
}
// We need context if module set to use context + no non-context fallback.
if (!$context && self::$useContext == self::USE_CONTEXT) {
$ms = 'Needs non-empty context when module localize_fields\'s \'Use translation context\' setting is context + no non-context fallback';
if (module_exists('inspect') && user_access('inspect log')) {
inspect_trace(NULL, array(
'category' => 'localize_fields',
'message' => $ms,
'severity' => WATCHDOG_WARNING,
));
}
else {
watchdog('localize_fields', __CLASS__ . '::' . __FUNCTION__ . ': ' . $ms . ', source[@source].', array(
'@source' => $source,
), WATCHDOG_WARNING);
}
// For what it's worth.
return t($source);
}
// We don't want to bother folks with question about whether the source is
// encoded; let's just assume it is.
return self::translateInternal($source, $context, TRUE);
}