0

I am trying to make mailing subject lines automatically bilingual by using Smarty code, but I am running into an issue as the required code easily busts the 128 max character length for subject values.

For example, this automatic bilingual subject value:

{capture assign=l}{contact.preferred_language}{/capture}{if $l eq 'en_CA'}Spring cleaning on May 11th{else}Nettoyage du printemps le 11 mai{/if}

Gives the error "Value for subject is 145 characters - This field has a maxlength of 128 characters". Of course the resulting subject text in the mailing will be much shorter, but the Smarty version is too long for CiviMail.

I can only think of 2 ways to overcome this 128 character limitation:

  • Change the subject field from a VARCHAR(128) to a VARCHAR(256) in the mailing DB table and it's matching maxlength value in the Mailing DAO code, but that would be an ugly and unmanageable hack when upgrading.
  • Find way to define a $lang Smarty variable in a global scope so it can be used in the subject line without having to "capture" the value directly in the subject line. i.e. add this bit of code in a template somewhere "{capture assign=lang}{contact.preferred_language}{/capture}" so this bit of code is not necessary directly in the subject value.

I can't be the only one who ran into this challenge. How would you solve it?

Thanks!

2 Answers 2

2

Also - you can skip the capture... as the token is resolved first

{if '{contact.preferred_language}' eq 'en_CA'}Spring cleaning on May 11th{else}Nettoyage du printemps le 11 mai{/if}

1
  • Oh, this works! The characters saved should be enough to allow for bilingual subjects. Thanks!
    – Mathieu
    Commented Apr 22 at 22:43
0

You can create a language specific message template if you have the Message Admin extension enabled (it ships with Core)

I just tested it with an Invoice & my contact with Catalan language got the Catalan language when I used Download Invoice

(I did have a funky moment on saving which I can't replicate - but the data is written to civicrm_translation)

enter image description here

1
  • Interesting! Unfortunately the mailing is a custom mass mailing and not a system workflow message.
    – Mathieu
    Commented Apr 22 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.