diff -u b/core/lib/Drupal/Core/Annotation/PluralTranslation.php b/core/lib/Drupal/Core/Annotation/PluralTranslation.php --- b/core/lib/Drupal/Core/Annotation/PluralTranslation.php +++ b/core/lib/Drupal/Core/Annotation/PluralTranslation.php @@ -19,7 +19,8 @@ * @code * label_count = @ PluralTranslation( * singular = "1 item", - * plural = "@count items" + * plural = "@count items", + * context = "cart_items", * ), * @endcode * Remove spaces after @ in your actual plugin - these are put into this sample @@ -44,11 +45,11 @@ class PluralTranslation extends AnnotationBase { /** - * The string for the singular case. + * The context the source strings belong to. * * @var string */ - protected $singular; + protected $context; /** * The string for the plural case. @@ -58,11 +59,21 @@ protected $plural; /** - * Constructs a PluralTranslation object. + * The string for the singular case. + * + * @var string + */ + protected $singular; + + /** + * Constructs a new class instance. */ public function __construct($values) { $this->singular = $values['singular']; $this->plural = $values['plural']; + if (isset($values['context'])) { + $this->context = $values['context']; + } } /** @@ -72,6 +83,7 @@ return array( 'singular' => $this->singular, 'plural' => $this->plural, + 'context' => $this->context, ); } only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php @@ -51,6 +51,11 @@ protected function setUp() { 'color' => 'yellow', 'uses' => array( 'bread' => t('Banana bread'), + 'loaf' => array( + 'singular' => '1 loaf', + 'plural' => '@count loafs', + 'context' => NULL, + ), ), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Banana', 'provider' => 'plugin_test', only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Annotation/PluralTranslationTest.php @@ -0,0 +1,66 @@ + '', + 'name' => '\Drupal\Core\Annotation\PluralTranslation unit test', + 'group' => 'System', + ); + } + + /** + * @covers \Drupal\Core\Annotation\PluralTranslation::get() ++ * ++ * @dataProvider providerTestGet + */ + public function testGet(array $values) { + $annotation = new PluralTranslation($values); + + $default_values = array( + 'context' => NULL, + ); + $this->assertEquals($values + $default_values, $annotation->get()); + } + + /** + * Provides data to self::testGet(). + */ + public function providerTestGet() { + $data = array(); + $data[] = array( + array( + 'singular' => $this->randomName(), + 'plural' => $this->randomName(), + 'context' => $this->randomName(), + ), + ); + $data[] = array( + array( + 'singular' => $this->randomName(), + 'plural' => $this->randomName(), + ), + ); + + return $data; + } + +}