You are here

protected static function LocalizeFields::translateInternal in Localize Fields 7

Does NOT check for '' nor all-digits source - callers must do that.

Parameters

string $source:

string $context:

boolean $encoded:

Return value

string

6 calls to LocalizeFields::translateInternal()
LocalizeFields::fieldAttachValidate in ./LocalizeFields.inc
Translates error messages created by implementations of hook_field_validate().
LocalizeFields::fieldAttachViewAlter in ./LocalizeFields.inc
Translates field view labels, and corrects decimal separator of decimals/floats.
LocalizeFields::fieldWidgetFormAlter in ./LocalizeFields.inc
Translates fields' labels, descriptions etc.
LocalizeFields::preElementValidate in ./LocalizeFields.inc
Custom element validator which performs no validation but translates the labels used in element validation by field types having an #element_validate function.
LocalizeFields::preprocessFieldMultipleValueForm in ./LocalizeFields.inc
Translates instance wrapper label and description when any/more values (cardinality not 1).

... See full list

File

./LocalizeFields.inc, line 180
Drupal Localize Fields module

Class

LocalizeFields
@file Drupal Localize Fields module

Code

protected static function translateInternal($source, $context, $encoded = FALSE) {
  $useContext = self::$useContext;
  $translated = !$useContext ? t($source) : t($source, array(), array(
    'context' => $context,
  ));
  if ($translated == $source) {
    if ($encoded && strpos($source, '&') !== FALSE) {

      // We do deliberately not use Drupal decode_entities() nor PHP
      // html_entity_decode(), because we want full control and only work on
      // specific entities.
      // If the label actually was encoded...
      if (($decoded = str_replace(self::$entitiesEncoded, self::$entitiesRaw, $source)) != $source) {
        if (($translated_decoded = !$useContext ? t($decoded) : t($decoded, array(), array(
          'context' => $context,
        ))) != $source) {

          // Re-encode after translation.
          return str_replace(self::$entitiesRaw, self::$entitiesEncoded, $translated_decoded);
        }
        elseif ($useContext == self::USE_CONTEXT_NONCONTEXT && ($translated_decoded = t($decoded)) != $source) {

          // Re-encode after translation.
          return str_replace(self::$entitiesRaw, self::$entitiesEncoded, $translated_decoded);
        }
      }
      elseif ($useContext == self::USE_CONTEXT_NONCONTEXT) {

        // ~ Fallback on no-context.
        return t($source);
      }
    }
    elseif ($useContext == self::USE_CONTEXT_NONCONTEXT) {

      // ~ Fallback on no-context.
      return t($source);
    }
  }
  return $translated;
}