Chris@0: t(). Otherwise create a new Chris@0: * \Drupal\Core\StringTranslation\TranslatableMarkup object. Chris@0: * Chris@0: * @param string $string Chris@0: * A string containing the English text to translate. Chris@0: * @param array $args Chris@0: * (optional) An associative array of replacements to make after Chris@0: * translation. Based on the first character of the key, the value is Chris@0: * escaped and/or themed. See Chris@0: * \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for Chris@0: * details. Chris@0: * @param array $options Chris@0: * (optional) An associative array of additional options, with the following Chris@0: * elements: Chris@0: * - 'langcode' (defaults to the current language): A language code, to Chris@0: * translate to a language other than what is used to display the page. Chris@0: * - 'context' (defaults to the empty context): The context the source Chris@0: * string belongs to. See the Chris@0: * @link i18n Internationalization topic @endlink for more information Chris@0: * about string contexts. Chris@0: * Chris@0: * @return \Drupal\Core\StringTranslation\TranslatableMarkup Chris@0: * An object that, when cast to a string, returns the translated string. Chris@0: * Chris@0: * @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat() Chris@0: * @see \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() Chris@0: * Chris@0: * @ingroup sanitization Chris@0: */ Chris@0: public function translate($string, array $args = [], array $options = []); Chris@0: Chris@0: /** Chris@0: * Translates a TranslatableMarkup object to a string. Chris@0: * Chris@0: * @param \Drupal\Core\StringTranslation\TranslatableMarkup $translated_string Chris@0: * A TranslatableMarkup object. Chris@0: * Chris@0: * @return string Chris@0: * The translated string. Chris@0: */ Chris@0: public function translateString(TranslatableMarkup $translated_string); Chris@0: Chris@0: /** Chris@0: * Formats a string containing a count of items. Chris@0: * Chris@0: * This function ensures that the string is pluralized correctly. Since Chris@0: * TranslationInterface::translate() is called by this function, make sure not Chris@0: * to pass already-localized strings to it. See Chris@0: * PluralTranslatableMarkup::createFromTranslatedString() for that. Chris@0: * Chris@0: * For example: Chris@0: * @code Chris@0: * $output = $string_translation->formatPlural($node->comment_count, '1 comment', '@count comments'); Chris@0: * @endcode Chris@0: * Chris@0: * Example with additional replacements: Chris@0: * @code Chris@0: * $output = $string_translation->formatPlural($update_count, Chris@0: * 'Changed the content type of 1 post from %old-type to %new-type.', Chris@0: * 'Changed the content type of @count posts from %old-type to %new-type.', Chris@0: * array('%old-type' => $info->old_type, '%new-type' => $info->new_type)); Chris@0: * @endcode Chris@0: * Chris@0: * @param int $count Chris@0: * The item count to display. Chris@0: * @param string $singular Chris@0: * The string for the singular case. Make sure it is clear this is singular, Chris@0: * to ease translation (e.g. use "1 new comment" instead of "1 new"). Do not Chris@0: * use @count in the singular string. Chris@0: * @param string $plural Chris@0: * The string for the plural case. Make sure it is clear this is plural, to Chris@0: * ease translation. Use @count in place of the item count, as in Chris@0: * "@count new comments". Chris@0: * @param array $args Chris@0: * An associative array of replacements to make after translation. Instances Chris@0: * of any key in this array are replaced with the corresponding value. Chris@0: * Based on the first character of the key, the value is escaped and/or Chris@17: * themed. See \Drupal\Component\Render\FormattableMarkup. Note that you do Chris@0: * not need to include @count in this array; this replacement is done Chris@0: * automatically for the plural cases. Chris@0: * @param array $options Chris@0: * An associative array of additional options. See t() for allowed keys. Chris@0: * Chris@0: * @return \Drupal\Core\StringTranslation\PluralTranslatableMarkup Chris@0: * A translated string. Chris@0: * Chris@0: * @see \Drupal\Core\StringTranslation\TranslationInterface::translate() Chris@0: * @see t() Chris@17: * @see \Drupal\Component\Render\FormattableMarkup Chris@0: * @see \Drupal\Core\StringTranslation\PluralTranslatableMarkup::createFromTranslatedString() Chris@0: */ Chris@0: public function formatPlural($count, $singular, $plural, array $args = [], array $options = []); Chris@0: Chris@0: }