On this page
class 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
- class \Drupal\Component\Annotation\AnnotationBase implements AnnotationInterface
- class \Drupal\Core\Annotation\PluralTranslation
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\AnnotationMembers
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. |
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Annotation!PluralTranslation.php/class/PluralTranslation/8.1.x