Drupal 8  8.0.2
TranslationInterface Interface Reference
Inheritance diagram for TranslationInterface:

Public Member Functions

 translate ($string, array $args=array(), array $options=array())
 
 translateString (TranslatableMarkup $translated_string)
 
 formatPlural ($count, $singular, $plural, array $args=array(), array $options=array())
 

Detailed Description

Interface for the translation.manager translation service.

Member Function Documentation

formatPlural (   $count,
  $singular,
  $plural,
array  $args = array(),
array  $options = array() 
)

Formats a string containing a count of items.

This function ensures that the string is pluralized correctly. Since TranslationInterface::translate() is called by this function, make sure not to pass already-localized strings to it. See PluralTranslatableMarkup::createFromTranslatedString() for that.

For example:

$output = $string_translation->formatPlural($node->comment_count, '1 comment', '@count comments');

Example with additional replacements:

$output = $string_translation->formatPlural($update_count,
'Changed the content type of 1 post from %old-type to %new-type.',
'Changed the content type of @count posts from %old-type to %new-type.',
array('%old-type' => $info->old_type, '%new-type' => $info->new_type));
Parameters
int$countThe item count to display.
string$singularThe string for the singular case. Make sure it is clear this is singular, to ease translation (e.g. use "1 new comment" instead of "1 new"). Do not use in the singular string.
string$pluralThe string for the plural case. Make sure it is clear this is plural, to ease translation. Use in place of the item count, as in "@count new comments".
array$argsAn associative array of replacements to make after translation. Instances of any key in this array are replaced with the corresponding value. Based on the first character of the key, the value is escaped and/or themed. See ::format(). Note that you do not need to include in this array; this replacement is done automatically for the plural cases.
array$optionsAn associative array of additional options. See t() for allowed keys.
Returns
A translated string.
See Also
::translate()
t()
Formatting
::createFromTranslatedString()

Implemented in TestTranslationManager, and TranslationManager.

Referenced by UnmetDependenciesException\getTranslatedMessage().

Here is the caller graph for this function:

translateString ( TranslatableMarkup  $translated_string)

Translates a TranslatableMarkup object to a string.

Parameters
\Drupal\Core\StringTranslation\TranslatableMarkup$translated_stringA TranslatableMarkup object.
Returns
string The translated string.

Implemented in TestTranslationManager, and TranslationManager.


The documentation for this interface was generated from the following file: