string = $string; $this->arguments = $arguments; $this->options = $options; $this->stringTranslation = $string_translation; } /** * Gets the untranslated string value stored in this translated string. * * @return string * The string stored in this wrapper. */ public function getUntranslatedString() { return $this->string; } /** * Gets a specific option from this translated string. * * @param $name * Option name. * * @return mixed * The value of this option or empty string of option is not set. */ public function getOption($name) { return isset($this->options[$name]) ? $this->options[$name] : ''; } /** * Gets all options from this translated string. * * @return mixed[] * The array of options. */ public function getOptions() { return $this->options; } /** * Gets all argments from this translated string. * * @return mixed[] * The array of arguments. */ public function getArguments() { return $this->arguments; } /** * Renders the object as a string. * * @return string * The translated string. */ public function render() { if (!isset($this->translatedMarkup)) { $this->translatedMarkup = $this->getStringTranslation()->translateString($this); } // Handle any replacements. if ($args = $this->getArguments()) { return $this->placeholderFormat($this->translatedMarkup, $args); } return $this->translatedMarkup; } /** * Magic __sleep() method to avoid serializing the string translator. */ public function __sleep() { return array('string', 'arguments', 'options'); } /** * Gets the string translation service. * * @return \Drupal\Core\StringTranslation\TranslationInterface * The string translation service. */ protected function getStringTranslation() { if (!$this->stringTranslation) { $this->stringTranslation = \Drupal::service('string_translation'); } return $this->stringTranslation; } }