Change language to send an email

It isn't something I do in my everyday life... In fact, it's the very first time I was required to implement this.

Scenario:

The administrator of a Drupal Commerce shop has to be able to send personalized emails to his clients. The email has to be personalized and the language of the email will have to change accordingly.

To facilitate the process for the administrator, I decided to create multilingual variables for some parts of the email and allow the administrator to change them from the UI with a common Drupal settings form.

The Problem:

Using variables is administrator-friendly. But when sending an email in English when the page is loaded in Greek means that any variable_get() calls will load the Greek text, even if the variable module is enabled. Variables are actually stored in memory after variable_initialize() has been called. As a result, you may change the global $language object to the language of your choice before printing any texts not wrapped in t(), but the variables will still hold the values of the old language.

The Solution:

Comments

Popular Posts