TranslationWrapper deprecated
class TranslationWrapper extends TranslatableMarkup (View source)
deprecated
Provides translatable string class.
Traits
Wraps __toString in a trait to avoid some fatals.
Properties
| protected string | $string | The string containing placeholders. |
from FormattableMarkup |
| protected array | $arguments | The arguments to replace placeholders with. |
from FormattableMarkup |
| protected string | $translatedMarkup | The translated markup without placeholder replacements. |
from TranslatableMarkup |
| protected array | $options | The translation options. |
from TranslatableMarkup |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from TranslatableMarkup |
Methods
Constructs a new class instance.
Returns a representation of the object for use in JSON serialization.
Replaces placeholders in a string with values.
Gets the untranslated string value stored in this translated string.
Gets a specific option from this translated string.
Magic __sleep() method to avoid serializing the string translator.
Gets the string translation service.
Details
__construct(string $string, array $arguments = [], array $options = [], TranslationInterface $string_translation = NULL)
Constructs a new class instance.
When possible, use the \Drupal\Core\StringTranslation\StringTranslationTrait $this->t(). Otherwise create a new \Drupal\Core\StringTranslation\TranslatableMarkup object directly.
Calling the trait's t() method or instantiating a new TranslatableMarkup object serves two purposes:
- At run-time it translates user-visible text into the appropriate language.
- Static analyzers detect calls to t() and new TranslatableMarkup, and add the first argument (the string to be translated) to the database of strings that need translation. These strings are expected to be in English, so the first argument should always be in English. To allow the site to be localized, it is important that all human-readable text that will be displayed on the site or sent to a user is made available in one of the ways supported by the
__toString()
Implements the magic __toString() method.
int
count()
Returns the string length.
string
jsonSerialize()
Returns a representation of the object for use in JSON serialization.
static protected string
placeholderFormat(string $string, array $args)
Replaces placeholders in a string with values.
static protected string
placeholderEscape(string|MarkupInterface $value)
Escapes a placeholder replacement value if needed.
protected
_die()
For test purposes, wrap die() in an overridable method.
abstract string|object
render()
Renders the object as a string.
string
getUntranslatedString()
Gets the untranslated string value stored in this translated string.
mixed
getOption(string $name)
Gets a specific option from this translated string.
array
getOptions()
Gets all options from this translated string.
array
getArguments()
Gets all arguments from this translated string.
__sleep()
Magic __sleep() method to avoid serializing the string translator.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.