You are here

public function i18n_string_object::format_translation in Internationalization 7

Format the resulting translation or the default string applying callbacks

There's a hidden variable, 'i18n_string_debug', that when set to TRUE will display additional info

File

i18n_string/i18n_string.inc, line 206
API for internationalization strings

Class

i18n_string_object
String object that contains source and translations.

Code

public function format_translation($langcode, $options = array()) {
  $options += array(
    'langcode' => $langcode,
    'sanitize' => TRUE,
    'cache' => FALSE,
    'debug' => $this
      ->textgroup()->debug,
  );
  if ($translation = $this
    ->get_translation($langcode)) {
    $string = $translation;
    if (isset($options['filter'])) {
      $string = call_user_func($options['filter'], $string);
    }
  }
  else {

    // Get default source string if no translation.
    $string = $this
      ->get_string();
    $options['sanitize'] = !empty($options['sanitize default']);
  }
  if (!empty($this->format)) {
    $options += array(
      'format' => $this->format,
    );
  }

  // Add debug information if enabled
  if ($options['debug']) {
    $info = array(
      $langcode,
      $this->textgroup,
      $this->context,
    );
    if (!empty($this->format)) {
      $info[] = $this->format;
    }
    $options += array(
      'suffix' => '',
    );
    $options['suffix'] .= ' [' . implode(':', $info) . ']';
  }

  // Finally, apply options, filters, callback, etc...
  return i18n_string_format($string, $options);
}