PluralTranslatableMarkup
class PluralTranslatableMarkup extends TranslatableMarkup (View source)
A class to hold plural translatable markup.
Traits
Wraps __toString in a trait to avoid some fatals.
Constants
| deprecated DELIMITER |
The delimiter used to split plural strings. This is the ETX (End of text) character and is used as a minimal means to separate singular and plural variants in source and translation text. It was found to be the most compatible delimiter for the supported databases. |
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 |
| protected int | $count | The item count to display. |
|
| protected string | $translatedString | The already translated string. |
Methods
Constructs a new PluralTranslatableMarkup object.
Returns a representation of the object for use in JSON serialization.
Replaces placeholders in a string with values.
Renders the object as a string.
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.
Constructs a new class instance from already translated markup.
Gets the plural index through the gettext formula.
Details
__construct(int $count, string $singular, string $plural, array $args = [], array $options = [], TranslationInterface $string_translation = NULL)
Constructs a new PluralTranslatableMarkup object.
Parses values passed into this class through the format_plural() function in Drupal and handles an optional context for the string.
__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.
string
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.
static PluralTranslatableMarkup
createFromTranslatedString(int $count, string $translated_string, array $args = [], array $options = [])
Constructs a new class instance from already translated markup.
This method ensures that the string is pluralized correctly. As opposed to the __construct() method, this method is designed to be invoked with a string already translated (such as with configuration translation).
protected int
getPluralIndex()
Gets the plural index through the gettext formula.