Jump to content

translate custom strings in email layouts


Recommended Posts

Hello, I have a custom email theme (derived from the "modern" theme), and I need to insert custom translatable text strings.
In the email layout twig files in /mails/themes/customtheme/core I am inserting the strings in this way

{{ 'Hi {customer_company_name},'|trans({}, 'Emails.Body', locale) }}

I would then need to be able to translate these strings in the shop languages by going in BO to Design -> Email theme -> Translate Emails.

Here I can though only see the strings that are in the default Prestashop email themes, the new ones are not showing up. Seems like there is an issue with the file scanner for the email folders, because when I insert custom strings in module templates, the file scanner retrieves them and they show up in the translation interface.

You can see in the attached screenshot that my string 'Hi {customer_company_name},' does not show up in the translation interface, but just the 'Hi {firstname}' is visible, which comes from the default email theme.

 

Does anyone know how I can do so that my custom strings show up in the translation interface?

I do not want to modify the HTML structure through the interface under International -> Translations, because I want to be able to regenarate the email layouts when changing the HTML structure in the twig files, without losing all my translations.

 

Thank you

immagine.png

Edited by mavalentin
add screenshot (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

In PrestaShop, the email translation system relies on the catalog generated from the available email templates. If your custom strings are not showing up in the translation interface, you may need to clear the cache and refresh the translation catalog.

Please follow these steps:

  1. Clear cache:
  • Go to your PrestaShop root folder.
  • Delete the content of the following folders:
  • /var/cache/dev/translations/
  • /var/cache/prod/translations
  1. Refresh the translation catalog:
  • Go to your PrestaShop back office.
  • Navigate to International -> Translations.
  • Select "Email translations" in the "Modify translations" section.
  • Choose the email theme (your custom email theme) and the language you want to translate.
  • Click the "Modify" button. This will refresh the translation catalog and should include your custom strings.

If your custom strings still do not show up in the translation interface, make sure that your custom email theme is correctly structured and your custom strings follow the correct syntax.

Additionally, you can try to add your custom strings directly to the Emails.Body.xlf translation files located in the /app/Resources/translations/ folder. Make sure to follow the correct format when adding the strings, and then clear the cache as mentioned earlier.

However, this approach is not recommended as it will make future updates more complicated, and you may lose your custom translations if the core files are updated.

Link to comment
Share on other sites

  • 6 months later...

In my case I have added a new layout using modern as a base and replacing all path to new folder.  It looked the cleanest way to deal with updates. 
I can regenerate mail templates with the new layout but I cannot see the new strings in the translation interface
I'm unsing prestashop 8.1 on php 8.2 and linux apache server in developer mode -> true. 

I have tried to clean all the possible caches and refresh translations catalogs, with no luck. 

 

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...