Handling declensions in emails

Dear Folks,

I run a small guesthouse and I’m setting up Mautic to take over most of the repetitive, guest related communication.

My software
Mautic 2.16.1
PHP 7.3

My problem
My audience is mainly Polish (according to some the most difficult language there) and we have seven cases for both pronouns and names.

Implications are, that depending on the context:

  • my name is Kacper, Kacpra, Kacprowi, Kacpra, Kacprem, Kacprze or Kacprze
  • singular, masculine pronoun is Pan, Pana, Panu, Pana, Panem, Panu or Panie

I compiled a database of 3000+ Polish names declensions and another one with 35 possible pronouns.

They are all scattered across a series of many emails. They are often parts of a dynamic content blocks inserted through Code Mode.

What’s the best way to merge it?

Starting points
I’m happy with neither, but I have no other ideas. I’m hoping you folks will help me come up with something smarter.

  1. Custom Fields for each Contact to hold all the cases, inserted through {contactfield=firstname-dative} or {contactfield=pronoun-dative}. Issues:
    - mess due to 14/21 additional fields for each contact
    - automatically populating fields with the right values
  2. Dynamic Content for the pronouns, inserted through {dynamiccontent=“Dynamic Content n”}. Issues:
    - messy code due to breaking large content containers into many small ones
    - mess in a dynamic content tab
    - labour intensive to implement - every email will have to have a copy of the same dynamic content boilerplate to set up
    - painful to maintain/update in case of bugs - every change will have to be made in every email

Just an association: Dud you look at https://github.com/Logicify/mautic-advanced-templates-bundle ?

2 Likes

Hey @ekke, it looks promising. I have never touched PHP, but I learned Handlebars once, so I’ll try to learn Twig from their documentation. I’ll let you know how it went. Thank you!

Yes, after a little bit of reading and tinkering, mautic-advanced-templates-bundle seems to be the solution for both.

Flexing names solution:

  1. Add nameFlex custom field in Settings
  2. Set nameFlex value for a given contact to an array of corresponding declensions like ["Kacper", "Kacpra", "Kacprowi", "Kacpra", "Kacprem", "Kacprze", "Kacprze"]
  3. Set a variable flex and filter it with json_decode inside the TWIG block of the email.
  4. Pull the chosen declension, pointing at it’s location in the array with {{flex[6]}}

Pronouns solution

  1. Basic if, elseif and else logic.

Example:

{% TWIG_BLOCK %}

{% set flex = lead.flex | json_decode %}

{% if lead.gender == 'm' %}<p>Szanowny Panie {{flex[6]}}</p>
{% elseif lead.gender == 'f' %}<p>Szanowna Pani {{flex[6]}}</p>
{% else %}<p>Dzień dobry {{flex[6]}}</p>
{% endif %}

{% END_TWIG_BLOCK %}

Output:

Szanowny Panie Kacprze

Namaste :pray:

2 Likes