Feeds uses Doctrine\Common\Inflector\Inflector class to automatically create plurals of entities and items.

This does not support other languages than English. The outcome is worse than using singular form where plural is needed.

Drupal core has better support for this, entities have label_plural property that can be translated.

Comments

mikran created an issue. See original summary.

megachriz’s picture

I noticed this too in the Dutch language. It always puts an 's' after the name of a content type, where using 'en' would make more sense in Dutch.

For example, I sometimes see this message:

4 Onderdeels bijgewerkt.

(meaning: updated 4 components)

While the correct Dutch phrase in this case would be:

4 onderdelen bijgewerkt.

I didn't see a way yet how to fix that. Content types don't have plural labels, just one label.

You say it happens for entity type names as well?

mikran’s picture

Status: Active » Needs review
StatusFileSize
new1.52 KB

Bundles do not yet support plural labels: #2765065: Allow plurals on bundle labels

This patch adds translatable plurals for entity types and uses singular form for bundle for now. IMO it is better to use translatable singular form instead of malformed plural.

mikran’s picture

You say it happens for entity type names as well?

Yes it does. I'm not sure why there is @item and @entity when both appear to be entities. It is really hard to translate this properly even with translated plural forms.

Status: Needs review » Needs work

The last submitted patch, 3: 3123396-2.patch, failed testing. View results

megachriz’s picture

It would be cool if we could fix this issue in a way that it still looks nice in English, for example "Created 6 articles" instead of "Created 6 Article".

Because in Drupal 9, Drupal core no longer has a dependency on doctrine/inflector. So if we keep using the inflector, then Feeds will be harder to install for non-composer users in Drupal 9. See also #3129114: Fix Drupal 9 test failures.

megachriz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.06 KB
new3.44 KB

I see the following interesting piece in the patch from #2765065-101: Allow plurals on bundle labels:

+++ b/core/lib/Drupal/Core/Config/Entity/EntityBundleWithPluralLabelsTrait.php
@@ -0,0 +1,141 @@
+  /**
+   * {@inheritdoc}
+   */
+  public function getSingularLabel() {
+    // Provide a fallback in case label_singular is not set yet.
+    if (empty($this->label_singular)) {
+      if ($label = $this->label()) {
+        $this->label_singular = mb_strtolower($label);
+      }
+    }
+    return $this->label_singular;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getPluralLabel() {
+    // Provide a fallback in case label_plural is not set yet.
+    if (empty($this->label_plural)) {
+      if ($label = $this->label()) {
+        $arguments = ['@label' => mb_strtolower($label)];
+        $options = ['langcode' => $this->language()->getId()];
+        $this->label_plural = new TranslatableMarkup('@label items', $arguments, $options);
+      }
+    }
+    return $this->label_plural;
+  }

For the content type 'Article' without specific singular and plural labels this would result into:

  • "Created 1 article" in the singular form.
  • "Created 6 article items" in the plural form.

This seems like a nice workaround. I see that in #2765065: Allow plurals on bundle labels, the label is also converted to lowercase. However, that would at least be incorrect for the German language (as also noted on that issue). But even in other languages you can't be sure whether it's correct to convert the label to lowercase. For example, on one site I have a content type called 'FAQ' - an abbreviation - and in that case I think it's better to keep it capitalized. In that case the messages in Feeds would become:

  • "Created 1 Article" in the singular form.
  • "Created 6 Article items" in the plural form.

The patch makes the plural bundle label "@label items" and hopefully updates all related tests.

megachriz’s picture

I ran the tests against D9 to check if there are no more mentions of Doctrine\Common\Inflector\Inflector in the code base. And this appears the case!

@mikran
What do you think of the patch in #7?

mikran’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • MegaChriz committed 0a8aec8 on 8.x-3.x authored by mikran
    Issue #3123396 by MegaChriz, mikran: Use the entity type's plural label...
megachriz’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for taking a look, @mikran

Committed #7.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.