diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js
index eed93f0..7d2478e 100644
--- a/core/modules/node/content_types.js
+++ b/core/modules/node/content_types.js
@@ -54,6 +54,19 @@
if (!$editContext.find('#edit-display-submitted').is(':checked')) {
vals.unshift(Drupal.t("Don't display post information"));
}
+ var singularLabel = $(context).find('#edit-label-singular').val();
+ vals.push(singularLabel ? Drupal.t("Singular '@label'", {'@label': singularLabel}) : Drupal.t('Requires a singular label'));
+ var pluralLabel = $(context).find('#edit-label-plural').val();
+ vals.push(pluralLabel ? Drupal.t("Plural '@label'", {'@label': pluralLabel}) : Drupal.t('Requires a plural label'));
+ var hasAllCountLabels = true;
+ $('#edit-label-count input[type="text"]', context).each(function () {
+ if (!$(this).val()) {
+ hasAllCountLabels = false;
+ return false;
+ }
+ });
+ vals.push(hasAllCountLabels ? Drupal.t("Count label variants defined") : Drupal.t('Requires count label variants'));
+
return vals.join(', ');
});
}
diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php
index f08286b..9cc870c 100644
--- a/core/modules/node/src/NodeTypeForm.php
+++ b/core/modules/node/src/NodeTypeForm.php
@@ -186,7 +186,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['display']['plural'] = [
'#type' => 'fieldset',
'#title' => $this->t('Singular and plural labels'),
- '#description' => $this->t('These are alternatives to the node type label for singular and plural cases.'),
+ '#description' => $this->t('These are lowercase alternatives to the node type label for singular and plural cases.'),
];
$form['display']['plural']['label_singular'] = [
'#type' => 'textfield',
@@ -205,7 +205,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['display']['label_count'] = [
'#type' => 'fieldset',
'#title' => $this->t('Count labels'),
- '#description' => $this->t('Count labels are used to build a text representation of a certain number of @label_plural. Token @count
is available and will be replaced with the number of @plural.', $arguments),
+ '#description' => $this->t('Count labels are used to build a text representation of a certain number of @plural. Token @count
is available and will be replaced with the number of @plural.', $arguments),
'#tree' => TRUE,
];
$plurals = $this->getNumberOfPlurals($type->language()->getId());
diff --git a/core/modules/node/src/Tests/NodeTypePluralLabelsTranslationTest.php b/core/modules/node/src/Tests/NodeTypePluralLabelsTranslationTest.php
new file mode 100644
index 0000000..4806c3c
--- /dev/null
+++ b/core/modules/node/src/Tests/NodeTypePluralLabelsTranslationTest.php
@@ -0,0 +1,125 @@
+save();
+
+ // Create and log in user.
+ $account = $this->drupalCreateUser([
+ 'administer content types',
+ 'administer node fields',
+ 'translate configuration',
+ ]);
+ $this->drupalLogin($account);
+
+ /** @var \Drupal\locale\PluralFormulaInterface $plural_formula */
+ $plural_formula = $this->container->get('locale.plural.formula');
+
+ // Workaround to register the Romanian and English language formulae in
+ // state. Without this the number of plurals is not correctly parsed.
+ $po_header = new PoHeader('ro');
+ $plural = $po_header->parsePluralForms('nplurals=3; plural=((n==1)?(0):(((n==0)||(((n%100)>0)&&((n%100)<20)))?(1):2));\n');
+ $plural_formula->setPluralFormula('ro', $plural[0], $plural[1]);
+ $plural = $po_header->parsePluralForms('nplurals=2; plural=(n > 1);\n');
+ $plural_formula->setPluralFormula('en', $plural[0], $plural[1]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function installParameters() {
+ $parameters = parent::installParameters();
+ // Install the site in Romanian language.
+ $parameters['parameters']['langcode'] = 'ro';
+ return $parameters;
+ }
+
+ /**
+ * Tests the node type translation.
+ */
+ public function testNodeTypeTranslation() {
+ /** @var \Drupal\Core\Language\LanguageManagerInterface $language_manager */
+ $language_manager = $this->container->get('language_manager');
+
+ $this->drupalGet('admin/structure/types/add');
+
+ // Romanian language has 3 plural variants
+ $this->assertFieldByName('label_count[0]');
+ $this->assertFieldByName('label_count[1]');
+ $this->assertFieldByName('label_count[2]');
+ $this->assertNoFieldByName('label_count[3]');
+
+ $edit = [
+ 'name' => 'Copil',
+ 'type' => 'child',
+ 'label_singular' => 'copil',
+ 'label_plural' => 'copii',
+ 'label_count[0]' => '1 copil',
+ 'label_count[1]' => '@count copii',
+ 'label_count[2]' => '@count de copii',
+ ];
+ $this->drupalPostForm(NULL, $edit, t('Save and manage fields'));
+
+ $edit = [
+ 'translation[config_names][node.type.child][name]' => 'Child',
+ 'translation[config_names][node.type.child][label_singular]' => 'child',
+ 'translation[config_names][node.type.child][label_plural]' => 'children',
+ 'translation[config_names][node.type.child][label_count][0]' => '1 child',
+ 'translation[config_names][node.type.child][label_count][1]' => '@count children',
+ ];
+ $this->drupalPostForm('admin/structure/types/manage/child/translate/en/add', $edit, t('Save translation'));
+
+ /** @var \Drupal\node\Entity\NodeType $node_type */
+ $node_type = NodeType::load('child');
+
+ // Test the default language (Romanian) original labels.
+ $this->assertEqual($node_type->label(), 'Copil');
+ $this->assertEqual($node_type->getSingularLabel(), 'copil');
+ $this->assertEqual($node_type->getPluralLabel(), 'copii');
+ $this->assertEqual($node_type->getCountLabel(1), '1 copil');
+ $this->assertEqual($node_type->getCountLabel(5), '5 copii');
+ $this->assertEqual($node_type->getCountLabel(20), '20 de copii');
+
+ // Load the English version of the 'child' node-type.
+ $original_language = $language_manager->getConfigOverrideLanguage();
+ $language_manager->setConfigOverrideLanguage(ConfigurableLanguage::load('en'));
+ /** @var \Drupal\node\Entity\NodeType $node_type */
+ $node_type = NodeType::load('child');
+ $language_manager->setConfigOverrideLanguage($original_language);
+
+ // Test the additional language (English) translated labels.
+ $this->assertEqual($node_type->label(), 'Child');
+ $this->assertEqual($node_type->getSingularLabel(), 'child');
+ $this->assertEqual($node_type->getPluralLabel(), 'children');
+ $this->assertEqual($node_type->getCountLabel(1), '1 child');
+ $this->assertEqual($node_type->getCountLabel(5), '5 children');
+ $this->assertEqual($node_type->getCountLabel(20), '20 children');
+ }
+
+}
diff --git a/core/modules/node/src/Tests/NodeTypeTest.php b/core/modules/node/src/Tests/NodeTypeTest.php
index 0d2d8de..4e08095 100644
--- a/core/modules/node/src/Tests/NodeTypeTest.php
+++ b/core/modules/node/src/Tests/NodeTypeTest.php
@@ -245,4 +245,42 @@ public function testNodeTypeNoContentType() {
$this->assertEqual(0, count($bundle_info->getBundleInfo('node')), 'The bundle information service has 0 bundles for the Node entity type.');
}
+ /**
+ * Tests singular/plural labels.
+ */
+ public function testPluralLabels() {
+ $account = $this->drupalCreateUser(['administer content types', 'administer node fields']);
+ $this->drupalLogin($account);
+
+ $edit = [
+ 'name' => 'Mouse',
+ 'type' => 'mouse',
+ ];
+ $this->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
+
+ $type = NodeType::load('mouse');
+
+ // Test fallback values.
+ $this->assertEqual($type->getSingularLabel(), 'mouse');
+ $this->assertEqual($type->getPluralLabel(), 'mouse items');
+ $this->assertEqual($type->getCountLabel(1), '1 mouse');
+ $this->assertEqual($type->getCountLabel(5), '5 mouse items');
+
+ $edit = [
+ 'label_singular' => 'mouse',
+ 'label_plural' => 'mice',
+ 'label_count[0]' => '1 mouse',
+ 'label_count[1]' => '@count mice',
+ ];
+ $this->drupalPostForm('admin/structure/types/manage/mouse', $edit, t('Save content type'));
+
+ $type = NodeType::load('mouse');
+
+ // Test user entered values.
+ $this->assertEqual($type->getSingularLabel(), 'mouse');
+ $this->assertEqual($type->getPluralLabel(), 'mice');
+ $this->assertEqual($type->getCountLabel(1), '1 mouse');
+ $this->assertEqual($type->getCountLabel(5), '5 mice');
+ }
+
}