Page 1 of 1

Other parameter than e-mail address to control Decorator?

Posted: Wed Mar 18, 2009 5:43 am
by HHahn
Can the Decorator only be "controlled" by e-mail addresses?

I have the following situation. A school website must send e-mails to pupils, teachers, parents etc, in order to tell them to register for the website. In Dutch, as in many other languages, there are two different forms of the 2nd person of the personal ('you') and possessive ('your') pronouns, viz. the "polite form" and the "informal form", depending on things like the age of the person addressed, relationship between sender and addressee, etc. Even the exact verb forms may be influenced by this. Other languages may be even much more complicated; for background information, please refer to http://en.wikipedia.org/wiki/T-V_distinction.

Of course, the recipient's e-mail address uniquely determines the wording to be used. But that would mean that for a hundred or more recipients several extra parameters must be defined (personal pronoun nominative, dative and accusative, possessive pronoun, verb forms depending on the personal pronoun, etc.), each of which can only have two different values, which is a lot of extra work and is error-prone (possibly causing impolite effects).

In short, what I would appreciate to have is a facility that allows me to specify, in addition to the current the personal data, one parameter per person determining whether or not the "informal" form should be used, and another list detemining what to use for either of these forms.

Example:

Code: Select all

array ("john.doe@here.tld" => array ("{name}" => "John Doe", "{formal}" => "[pol]"),
       "peter.johnson@elsewhere.tld" => array ("{name}" => "Peter Johnson", "{formal}" => "[inf]"),
etc.
and another list:

Code: Select all

array ("{u_je}" => array ("[pol]" => "u", "[inf]" => "je"),                             // pers. pron., unstressed
       "{u_jij}" => array ("[pol]" => "u", "[inf]" => "jij"),                             // pers. pron., stressed, nominative
       "{u_jou}" => array ("[pol]" => "u", "[inf]" => "jou"),                          // pers. pron., stressed, dative/accusative
       "{uw_jouw}" => array ("[pol]" => "uw", "[inf]" => "jouw"),                 // poss. pron.
       "{hebt_heb}" => array ("[pol]" => "hebt", "[inf]" => "heb"),               // verb form
       "{kunt_kun}" => array ("[pol]" => "kunt", "[inf]" => "kun"),                // verb form
etc.
(where "[pol]" stands for "polite form" and "[inf]" for "informal form"),
or something like this. (The exact entries will of course depend on the actual text.)

In the decorator as it is now, I should specify all of these parameters for every single recipient, which is a lot of extra work and is error-prone (possibly causing impolite effects).

In short: there is a need for more parameters, which do not depend on the exact person, but on the category he belongs to. (Many more applications are possible. Think of address change notices, where some recipients must be informed about your undisclosed phone number, or you company phone number, while others should not.)

The only way I see now, is to use a separate PHP function that first chooses the correct pronouns and verb forms (generally: the correct category-dependent values), and then automatically builds the array for the decorator. But this will most likely undo the advantages of the clever cache useage by SwiftMailer, implying that the entire Decorator is not of much use and the desired effects can also be simply obtained by the PHP function str_replace().

What I am asking, is in fact a "two-level replacement". I am aware that you will not have this available "tomorrow". But if you manage to realise something like this, it will make SwiftMailer extra attractive to be used with foreign languages.

Re: Other parameter than e-mail address to control Decorator?

Posted: Wed Mar 18, 2009 8:20 pm
by Chris Corbyn
I need to add the functionality that existed in version 3. Basically you could do this (yes, still based on email addresses, but with a little extra control):

Code: Select all

class MyReplacements implements Swift_Plugins_Decorator_ReplacementsFinder {
  public function getReplacementsFor($email) {
    return array('{foo}' => 'bar', '{zip}' => 'button');
  }
}
 
$plugin = new Swift_Plugins_DecoratorPlugin(new MyReplacements());
 
Of course, the logic inside getReplacementsFor() can do any kind of lookup from a database.

I overlooked this feature when rewriting for version 4 and basically it will be re-added.

Re: Other parameter than e-mail address to control Decorator?

Posted: Thu Mar 26, 2009 11:42 am
by HHahn
Do I correctly understand that this is currently not possible in version 4.0 and I have to wait for 4.1? If so, do you have any idea when version 4.1 will be available (not as an beta version, but a "final" one)?

Re: Other parameter than e-mail address to control Decorator?

Posted: Thu Mar 26, 2009 11:58 pm
by Chris Corbyn
HHahn wrote:Do I correctly understand that this is currently not possible in version 4.0 and I have to wait for 4.1? If so, do you have any idea when version 4.1 will be available (not as an beta version, but a "final" one)?
It's now available in 4.0, sorry I forgot to come back here and post a link:

http://swiftmailer.org/docs/decorator-p ... placements

EDIT | 4.1 is at least 2 months away. A lot of work goes into this stuff :)