The file profiles/commerce_kickstart/modules/contrib/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_area_line_item_summary.inc has a a snippet of slightly incorrect code. Slightly - cause it works fine in English, but this code knows nothing to do with 3 forms of plurals in Russian.

'quantity_label' => format_plural($quantity, 'item', 'items', array(), array('context' => 'product count on a Commerce order')),

So I had to wrap this code into regex replacement (it cuts the first number):

'quantity_label' => preg_replace( '/^[0-9]*\s+(.*)/', '${1}', format_plural($quantity, '1 item', '@count items', array(), array('context' => 'product count on a Commerce order'))),

Comments

bojanz’s picture

Project: Commerce Kickstart » Commerce Core
Version: 7.x-2.0 » 7.x-1.x-dev
Component: Code » Cart
Priority: Minor » Normal
Status: Needs work » Active

This is a Commerce issue. And we definitely can't fix it with a regular expression ;)

The recommended way to use format_plural is format_plural($quantity, '1 item', '@count items', array(), array('context' => 'product count on a Commerce order')), which should work in your case (can you check?)

And that's exactly what Commerce is doing for quantity, but not quantity_label, not sure why. Perhaps Ryan will have more insight.

rszrama’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

The function is being used here as specified, it's just separating out the quantity from the label for the purposes of theming (i.e. having a wrapper around the number separate from the label). We definitely don't want a regex in the code, but I also don't think I understand why this isn't working for you or why this isn't but any other format_plural() does. Can you provide more info?

CSoft’s picture

but this code knows nothing to do with 3 forms of plurals in Russian

Вы пишете про 5 items вместо 5 товаров, например? Просто недопереведено нашими коллегами. Зайдите в

/admin/config/regional/translate/translate

в фильтр вбейте "@count items" и переведите как "@count товара".

Затем ищем следующую форму: "@count[2] items". Переводим её: "@count[2] товаров".

Ну и конечно следим, чтобы правки делались в контексте product count on a Commerce order. И всё, всё будет работать как положено.

=============

Sorry for the answer in Russian, it concerns only the problem of our localization :)

glebgo’s picture

The thing is that when you have cart block displayed, summary with total quantity should have 3 different forms, but in case of 'quantity_label' programmatically configured to have only 2: 'item', 'items' - there is no chance. With translation we could only have 2 plural forms in Russian: translation of 'item, and 'items', but it's necessary to have 3. Please, correct me if I'm wrong or misunderstand something.

CSoft’s picture

With translation we could only have 2 plural forms in Russian

No, in our Russian language is 3 plural forms in this case. For example:

1 товар
2 товара
5 товаров

guy_schneerson’s picture

Same issue, If I understand it correctly, the numbering go like this:
1 товар,
2-4 товара,
5 -20 товаров

After 21 they start from 1 again but this time in cycles of 10:
21 товар,
22-24 товара,
25-30 товаров

31 товар etc
32-34 товара,
35-40 товаров

guy_schneerson’s picture

made correction to #6 changed "2-3" to "2-4"

pere orga’s picture

Issue summary: View changes

Can Drupal do this? Use multiple plural forms?

pere orga’s picture

Status: Postponed (maintainer needs more info) » Active
rootwork’s picture