It is displayed at the shopping cart block and summary.
I can deactivate/activate to print this in the corresponding Views (Footer: "Commerce Line Item: Line item summary" → "Item quantity").
It prints as "1 item", "2 items", "3 items" and so on.

How can I translate this?

I'm not sure which string is the right one. To test it I translated all strings that look like the right one, but none of them worked. It always prints as "item"/"items" for all languages.

Comments

rszrama’s picture

Status: Active » Fixed

If you look in commerce_line_item_handler_area_line_item_summary.inc, you'll see near line 123 where format_plural() is being called to prepare this quantity string. You should be able to translate "1 item" and "@count items" to whatever you need.

no2e’s picture

Status: Active » Fixed

You should be able to translate "1 item" and "@count items" to whatever you need.

Hmm, that doesn't work.

singular

  1. At /admin/config/regional/translate/translate I search for "1 item".
  2. I get two results, both in "Built-in interface":
    • "1 item" (with Context: "product count on a Commerce order")
    • "Shopping cart (1 item)"
  3. I translate it (for German) to "1 Foobar".
  4. I clear caches and change language to German → shopping cart prints "1 item" :(

plural

  1. At /admin/config/regional/translate/translate I search for "@count items".
  2. I get two results, both in "Built-in interface":
    • "@count items" (with Context: "product count on a Commerce order")
    • "Shopping cart (@count items)"
  3. I translate it (for German) to "@count Foobars".
  4. I clear caches and change language to German → shopping cart prints "2 items" :(

Problem with i18nviews?

I use Internationalization Views (i18nviews). But after my first test I changed Views translation method to "Core" (at /admin/structure/views/settings/advanced) and refreshed all strings → still doesn't work.

Even stringoverrides doesn't work …

Even using a string override doesn't work for this string. When I overwrite (for English) the string "1 item" with "1 foobar" (and use the Context "product count on a Commerce order"), nothing changes.

no2e’s picture

Status: Fixed » Active

(oops, forgot to change status; … don't know if this is now a bug or still a support request?)

rszrama’s picture

Status: Fixed » Active

I still think it should be a support request, but the issue appears to be centered around either that these strings are coming through format_plural() and therefore aren't being translated properly for some reason or that these strings are being passed as variables to a theme function. But honestly, neither of these seems like the real issue, because I don't know of any reason for them not to work.

no2e’s picture

Hmm … anything I could do to test? (can't program, though :/)

If I remember correctly, the translation worked some weeks/months ago when I was building the site - I think it was with Commerce 7.x-1.1. But I'm not sure about it.


Because I want to go live in the next days, I would have to use some JavaScript to replace and translate the string on the client-side … which is, of course, really ugly.

didaka’s picture

I got it translatable.
I used l10n_client to do my translation on screen and it turned out that the string to be translated is not @count items. It is only items and item in singular form.

didaka’s picture

Status: Active » Closed (works as designed)
igi’s picture

Drupal core 7.22, commerce_kickstart 2.9 (commerce_kickstart-7.x-2.9)

file:
/profiles/commerce_kickstart/modules/contrib/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_area_line_item_summary.inc
Change line 116
// 'quantity_label' => format_plural($quantity, 'item', 'items', array(), array('context' => 'product count on a Commerce order')),
to:
'quantity_label' => format_plural($quantity, t('item'), t('items'), array(), array('context' => 'product count on a Commerce order')),

nessunluogo’s picture

Issue summary: View changes
Status: Closed (works as designed) » Needs work
StatusFileSize
new1.46 KB

Drupal core 7.41, commerce_kickstart 2.30

After two years I had the same issue. #8 worked fine, so I made a patch where the t() is applied to both 'quantity' and 'quantity_label' elements of the array.

It needs testing, but I hope it can help.

rootwork’s picture

Title: How to translate the "Item quantity" in "Line Item Summary" (Shopping cart)? » Make item/items translatable in line item summary of shopping cart
Version: 7.x-1.2 » 7.x-1.x-dev
Category: Support request » Feature request
Status: Needs work » Needs review
StatusFileSize
new1.29 KB
new2.24 KB

The existing state (redeclaring a gigantic function that does a ton of stuff in template.php or a custom module) seems like a real hassle, and it seems like it'd be useful to just have these strings translatable.

Not even just for internationalization, but let's say your store sells only kittens -- wouldn't it be nice to be able to use String Overrides or a quick $conf setting so that your cart says "1 kitten, 2 kittens, etc."? Come on. More kittehs!

The patch in #9 was against a Commerce Kickstart install, so I've updated it to be specific to the module. But it'd be nice to see this reviewed and committed. It seems like an easy win.

Status: Needs review » Needs work
rootwork’s picture

Oh, right, as @nessunluogo said, it needs updated tests. So maybe not as "easy" of a win. But still worth pursuing, commerce maintainers?

perarg’s picture

patch #10, worked for me too. I use D7 7.50 and Commerce 2.x

nachus’s picture

Found the same problem. The patch fix it. Thanks!

nachus’s picture

Found the same problem. The patch fix it. Thanks!

thomas.wardin’s picture

For version 8.x-2.33

Same applies to the summary block. Currently it relies on "item" or "items" translated elsewhere. But in order for it to be specifically translatable, line 173 of commerce/modules/cart/src/Plugin/Block/CartBlock.php should read
'#count_text' => $this->formatPlural($count, t('@count item'), t('@count items')),