While extracting pot files from ecommerce modules, i've found some wrong usage of t() and form_plural() in cart.module, ecommailer.module, and product.module.

basically, there was t() functions calls instead of strings used in form_plural(), which is not correct as form_plural calls in turn t(). (http://drupaldocs.org/api/head/function/format_plural). and there was also php variables concatenated to strings in t(), instead of supplying them as parameter to the function, making a single translated string for each variable values.

patch is attached to correct the function calls.

additionnally, i also had errors in product.module, but they need to be discussed before fixing :)

some t() functions are called with an object value instead of strings, line 995 (there's also the same thing for a form_plural:

t($p->notification->subject, $variables), t($p->notification->body, $variables)

the $p->notification->subject/body should already be translated, if i'm not mistaken, as they are entered by the shop admin. so we could simply remove the t() call, but $variables is an array containing all values for subsitition (%site, %renewal_link, ...). i think the t() function call also handle the feature of replacing values in notification emails, so we cannot remove the t() calls without removing this, still if i'm not mistaken of course. but in that case, i don't really like the idea to use t() for this. but i'll look at it further.

the last issue if with a plural form in product.module at line 877, but i'll product a patch for solving it, as it leads to a lot of translation of already translated items, including passing a translated string to strtotime, so this has to be studied a bit more :)

thanks

Comments

sin’s picture

Version: » 4.6.x-1.x-dev
Component: product.module » store.module
Category: bug » task
Status: Needs review » Active

I also fixing plural forms in ecommerce for translation.
I found some incorrect (manual) plural formatting which was impossible to translate on my 3-plural form language without altering the code.
Here they are:

store.module: line 1258
was:

    $r = ($numset == 1) ? t('result') : t('results');
    $output .= "<h2>$numset $r found</h2>";

fixed:

    $r = format_plural($numset, 'result', '%count results');
    $output .= '<h2>'.$r.' '.t('found').'</h2>';

cart.module: line 126
was:

    $item_suffix = ($item_count == 1) ? t('item') : t('items');
    $output .= '<div class="item-count">'. t("%item_count %item_suffix in %your_cart", array("%item_count" => $item_count, "%item_suffix" => $item_suffix, "%your_cart" => l(t("your cart"), "cart/view"))). "</div>\n";

fixed:

    $item_suffix = format_plural($item_count, 'item', '%count items');
    $output .= '<div class="item-count">'. t("%item_suffix in %your_cart", array("%item_suffix" => $item_suffix, "%your_cart" => l(t("your cart"), "cart/view"))). "</div>\n";

Please include my fixes to your patch, I am not familiar with cvs and diff :)

syllance’s picture

Status: Active » Needs work

i'll double check and roll a patch with the fixes you sent. I've some more to add too, and needs to product a 4.6 patch, and a head patch.

this should be available very soon, and i'm moving this to code needs work until i finish the patches.

thanks

syllance’s picture

Category: task » bug
Status: Needs work » Needs review
StatusFileSize
new7.17 KB

Here's the patch that fixes previously listed problems with t() and format_plural().

I've merged titmouse and my changes.

Note that I've modified calls to format_plural added by titmouse to use "%count " even for singular.

I've also fixed some issues with translating some submit buttons. Not all of the form_submit calls were using t() function to translate the buttons, and I also modified store_admin to handle translated terms in the case ($op) checks. I also fixed the Search feature wich was not working with my 4.6 sandbox ($op was check for 'Search', where it should be t('Search') when using translated submit buttons.

Please find the patch attached for 4.6 ecommerce, and let me know if that helps or breaks :)

i'm moving the thread to code need review. I'll create an alternate one for HEAD patch, which I'm still working on.

thanks for reading

matt westgate’s picture

Status: Needs review » Fixed

Committed. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)