Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: switch language of message sent from admin panel
    text
    copied!<p>I have a model, Order, that has an action in the admin panel that lets an admin send information about the order to certain persons listed that order. Each person has language set and that is the language the message is supposed to be sent in.</p> <p>A short version of what I'm using:</p> <pre><code>from django.utils.translation import ugettext as _ from django.core.mail import EmailMessage lang = method_that_gets_customer_language() body = _("Dear mister X, here is the information you requested\n") body += some_order_information subject = _("Order information") email = EmailMessage(subject, body, 'customer@example.org', ['admin@example.org']) email.send() </code></pre> <p>The customer information about the language he uses is available in <code>lang</code>. The default language is en-us, the translations are in french (fr) and german (de).</p> <p>Is there a way to use the translation for the language specified in <code>lang</code> for <code>body</code> and <code>subject</code> then switch back to en-us? For example: <code>lang</code> is 'de'. The subject and body should get the strings specified in the 'de' translation files.</p> <p><strong>edit:</strong></p> <p>Found a solution.</p> <pre><code>from django.utils import translation from django.utils.translation import ugettext as _ body = "Some text in English" translation.activate('de') print "%s" % _(body) translation.activate('en') </code></pre> <p>What this does it take the <code>body</code> variable, translates it to German, prints it then returns the language to English. </p> <p>Something like</p> <pre><code>body = _("Some text in English") translation.activate('de') print "%s" % body </code></pre> <p>prints the text in English though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload