PluralTranslation

Defines an annotation object for strings that require plural forms.

Note that the return values for both 'singular' and 'plural' keys needs to be passed to \Drupal\Core\StringTranslation\TranslationInterface::formatPlural().

For example, the annotation can look like this:

  label_count = @ PluralTranslation(
    singular = "@count item",
    plural = "@count items",
    context = "cart_items",
  ),

Remove spaces after @ in your actual plugin - these are put into this sample code so that it is not recognized as annotation.

Code samples that make use of this annotation class and the definition sample above:

  // Returns: 1 item
  $entity_type->getCountLabel(1);

  // Returns: 5 items
  $entity_type->getCountLabel(5);

Hierarchy

See also

\Drupal\Core\Entity\EntityType::getSingularLabel()

\Drupal\Core\Entity\EntityType::getPluralLabel()

\Drupal\Core\Entity\EntityType::getCountLabel()

Related topics

Annotation for translatable text
Describes how to put translatable UI text into annotations.
Annotations
Annotations for class discovery and metadata description.

File

core/lib/Drupal/Core/Annotation/PluralTranslation.php, line 43

Namespace

Drupal\Core\Annotation

Members

Name Modifiers Type Description
AnnotationBase::$class protected property The class used for this annotated class.
AnnotationBase::$id public property The annotated class ID.
AnnotationBase::$provider protected property The provider of the annotated class.
AnnotationBase::getClass public function Gets the class of the annotated class. Overrides AnnotationInterface::getClass
AnnotationBase::getId public function Gets the unique ID for this annotated class. Overrides AnnotationInterface::getId
AnnotationBase::getProvider public function Gets the name of the provider of the annotated class. Overrides AnnotationInterface::getProvider
AnnotationBase::setClass public function Sets the class of the annotated class. Overrides AnnotationInterface::setClass
AnnotationBase::setProvider public function Sets the name of the provider of the annotated class. Overrides AnnotationInterface::setProvider
PluralTranslation::$context protected property The context the source strings belong to.
PluralTranslation::$plural protected property The string for the plural case.
PluralTranslation::$singular protected property The string for the singular case.
PluralTranslation::get public function Gets the value of an annotation. Overrides AnnotationInterface::get
PluralTranslation::__construct public function Constructs a new class instance.
doc_Drupal
2016-10-29 09:34:20
Comments
Leave a Comment

Please login to continue.