"Email an order invoice" rule action should provide translation ability via Rules Translation module such as "Send mail" rule action does.

In that way, we could localize the "Your Order at [store:name]" subject of email sent to customer after checkout and "New Order at [store:name]" of email sent to admin.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DanZ’s picture

You can use https://drupal.org/sandbox/DanZ/1847134 to register multiple order invoice templates. Each one could be in a separate language.

Then, you could set up multiple similar rules to trigger the action of sending the invoices. Each rule would have different conditions (probably on the order country). Each rule would send a different invoice.

Meanwhile, the templates do have their text wrapped in t(), so it should be possible to do translation that way somehow. For instance:

            <p><b><?php print t('An account has been created for you with the following details:'); ? ></b></p>
mandreato’s picture

Thanks Dan for the suggestion, but your module fits more complex situations.
In my case, the template is just OK: the sent email body is in the language the customer used during checkout. Instead the email subject is always the same because the rule action does not support localization.

DanZ’s picture

Ah, I see what you mean.

If you can find the code (registration, etc.) for the Send mail Rule action, maybe we can figure out what makes it translatable, and then do the same thing to the Ubercart action.

Note: uc_cart.rules_default.inc has:

'subject' => t('New Order at [store:name]'),

Apparently, this is not enough to make it translatable in Rules, right?

mandreato’s picture

Indeed, I tried to translate "Your Order at [store:name]" on .../admin/config/regional/translate/translate, but it simply changes permanently: it remains not sensitive to language.

I think that, in order to integrate with Rules Translation module, the uc_order_email_invoice should be modified in the same way of rules_action_mail system.rules.inc, but I'm too inexperienced to figure out how...

DanZ’s picture

Status: Active » Needs review
FileSize
742 bytes

Well, system rules_action_mail action has the following promising bit of code:

        'language' => array(
          'type' => 'token',
          'label' => t('Language'),
          'description' => t('If specified, the language used for getting the mail message and subject.'),
          'options list' => 'entity_metadata_language_list',
          'optional' => TRUE,
          'default value' => LANGUAGE_NONE,
          'default mode' => 'selector',
        ),

What happens if you stick that into the action for e-mailing an order invoice? Not knowing a thing about translation, I don't even know how to test it. Chances are that something needs to be done on the back end to actually use whatever language gets entered. Give this patch a try and let us know what happens.

DanZ’s picture

Ok, that patch won't do the whole job. There is some backend code. While looking for more, though, look what I found in function uc_order_action_email_invoice():

    $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $from);

This means that, when sending the e-mail message, the rule action attempts to translate the message into the language used by the customer being notified (or the default site language). So, the feature you want is probably already there.

Using this requires that you enable languages for your site and that the individual users select one of them. You should also select a default language for your site. Once again, I have no idea how to do this. However, start by enabling the "Locale" and "Content translation" modules and look at admin/config/regional.

If that's no good, have a look at the following completely untested (probably buggy) patch. It's supposed to let you specify a language on the action. If the customer selects his own language, it will use his language. If not, it will use the language specified in the action.

DanZ’s picture

Category: feature » support

Since the functionality is supposed to already be there, let's make this a support request. If it genuinely doesn't work, we can turn it into a bug report.

mandreato’s picture

@DanZ the site already has Locale and Content translation enabled, plus i18n. There are two language installed: english and italian and the customer receives the email body in its correct localization: when checkout is done from english pages, then the email is sent in english; when the checkout is done from italian, the email is italian.
This because the rule's action uses the invoice template as body and it is translated correctly by itself.

The patch #6, which I've tested few minutes ago, adds the ability to specify which language to use when sending the email, but we know that part is already correct. So I think the patch is unnecessary.

Instead, the real problem is on the subject of the email, which is an attribute of the rule action (not a token) and it is a sort of hard code: it remains the same independently from the checkout language.

The Rules module provides a way to localize the action attributes via Rules Translation submodule: it adds a "Translate" tab on the rule editor where to localize the attributes of the rule action.

Actually, the "Email an order invoice" action provides only the "Configuration name" as translatable string (basically the administration title of the rule). Whilst, the "Send mail" action (a standard Rules action), exposes the subject and the message too.

I think that the difference is in the rule action definition on the UC code, but I've big trouble to delve it on PHP...

Maybe, a workaround for reaching the goal would be to define a custom translatable token/variable to use in the subject. I'll try it...

DanZ’s picture

Category: feature » support
FileSize
415 bytes

Ooooohhhh. Thanks for the explanation. It finally made me look in the right place.

If the answer is what I think it is, this is breathtakingly simple. Try the following patch (you could easily do it by hand). It should give you exactly what you want.

That's what I get for not reading the docs.

DanZ’s picture

Category: support » feature

Oh, and if the above patch in #9 works, this would indeed be a feature request, since this would be good for general use.

longwave’s picture

Category: support » feature
FileSize
792 bytes

@DanZ: Thanks for finding this in the Rules API. I think we should add translatability to the "Send an order email" action at the same time.

DanZ’s picture

Good idea.

@mandreato, if you can test the patch in #11 and confirm that it works, it can be committed to the -dev branch and eventually released in 3.3.

mandreato’s picture

Status: Needs review » Reviewed & tested by the community

Patch #11 worked like a charm !
Thank you guys.

longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed #11. Thanks for the test report!

DanZ’s picture

Wow.... If only all features could be requested, analyzed, developed, improved, tested, approved, and committed in three days....

Status: Fixed » Closed (fixed)

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

Graham Leach’s picture

Issue summary: View changes

@longwave,

>@DanZ: Thanks for finding this in the Rules API.
> I think we should add translatability to the "Send an order email" action
> at the same time.

I am suspecting that this functionality was NOT added to the "Send an order email" action as I am struggling with just that problem...or was it?

g.
---