Setting Locale for email template in Magento

Setting Locale for email template in Magento

October 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Setting Locale for email template in Magento

Setting Locale for Custom Email Templates in Magento

As a senior developer at LaravelCompany, I frequently receive questions from our clients about customizing email templates in Magento. In this post, we’ll address an issue raised by a client who is struggling to send localized emails based on the store’s locale.

Identifying the Problem

The client has a Magento 1.4 installation that sends a custom email when orders are put on hold. The current implementation works perfectly for English emails but fails to send localized emails for German stores. The holdAction method used looks like this:

public function holdAction()
{
    // ... (rest of the method)
    $emailTemplate  = Mage::getModel('core/email_template')
            ->loadDefault('customer_payment_declined');
    // ... (rest of the method)
}

The issue lies in how the email template is loaded and processed. The loadDefault method retrieves the English version of the template, regardless of the store’s locale.

Understanding the Email Template System

Magento uses a system of default templates that can be overridden or customized for specific purposes. By default, these templates are stored under app/locale/en_US/template/customer/email/. The file names correspond to the email templates available in the admin panel.

To send localized emails, we need to ensure that Magento loads the correct template based on the store’s locale.

Loading Templates Based on Locale

The key to solving this issue is to modify how the email template is loaded. Instead of using loadDefault, which only retrieves the English version, we can use the sendTransactional method and specify the template ID directly.

Here’s an updated version of the critical section:

$sender = Mage::getStoreConfig('trans_email/ident_general/email');
$templateId = 'customer_payment_declined';
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');

Mage::getModel('core/email_template')
    ->sendTransactional(
        $templateId,
        $senderName,
        $sender,
        array($order->getCustomerEmail()),
        array(
            'order' => $order,
            'customername' => $order->getCustomerName()
        )
    );

In this updated code:

  1. We retrieve the sender email and name from the Magento configuration.
  2. We specify the template ID directly as a string (in this case, 'customer_payment_declined').
  3. We use the sendTransactional method, passing in the template ID, sender name, sender email, recipient email, and an array of variables for the template.

This approach ensures that Magento loads the correct version of the template based on the store’s locale.

Testing the Solution

To test this solution:

  1. Make sure your custom email template is available under app/locale/de_DE/template/customer/email/ for German stores.
  2. Verify that the trans_email configuration is set correctly in the admin panel, with the appropriate sender details for each store view.
  3. Place an order through a German store and put it on hold to trigger the holdAction.
  4. Check if you receive the localized email.

Conclusion

In this post, we’ve addressed a common issue faced by Magento developers when working with custom email templates - ensuring that emails are localized based on the store’s locale. By understanding how Magento loads these templates and using the sendTransactional method correctly, we can send accurate and localized emails to our customers.

Remember, if you’re looking for more advanced solutions or need expert assistance in your Magento development projects, feel free to reach out to the team at LaravelCompany. We provide comprehensive services tailored to your specific needs.

Magento 1 API Themes Admin

Our network