0

For the shipment email, I get the payment info from a third party extension. But the info field names are in English, while the rest of the email is in German. After some bug searching I found that the extension always returns the payment info in the backend locale, which is set to English.

German frontend with English backend German frontend with German backend

What I want to know is: How does Magento decide which language it uses for translation, when frontend and backend use different languages? Is there a way to keep the backend in English while still using this extension to get the payment info for the shipment email? The same payment info is shown in the backend when viewing order information, so I'd need both translations to work.

This how one of the fields is set in the code:

$data[(string)__('Payment reference:')] = $sTransId;

At that point, $this->area is set to 'frontend', but it seems that this information isn't used.

0

to avoid sending mail with the backend ID you have to emulate the store around code where data are fetch and email is send.

For that you can use:

$this->emulation->startEnvironmentEmulation($storeId); // $storeId from the payment info
// fetch data & send email
$this->emulation->stopEnvironmentEmulation();

With that data - including translations - are fetch with the right scope.
It is a reccurent issue when you are working with backend tasks like emails.

Sources:
- https://webkul.com/blog/magento2-store-emulation/
- http://davemacaulay.com/emulate-store-magento-2/

  • I've built a plugin to emulate the environment using my store ID and Area::AREA_FRONTEND, but still the translation uses the backend locale. $this->emulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND); try { $result = $proceed(); } catch (\Exception $e) { $this->emulation->stopEnvironmentEmulation(); throw $e; } – Maximilian Fickers Sep 6 '18 at 14:19
  • Simple question, did you try without any Area? Only $this->emulation->startEnvironmentEmulation($storeId);? Did you deploy your translations correctly? magento.stackexchange.com/a/142291/33619 – Matthéo Geoffray Sep 7 '18 at 9:20
  • I've got it to work by injecting the Framework\TranslateInterface and setting the locale directly. It's not pretty, but still better than hardcoding the translations. – Maximilian Fickers Sep 7 '18 at 13:20
0

Since the word is coded with the translation method, Magento get it like this:

app/code/{Vendor}/{name}/i18n/en_US.csv, en_US.csv exemple for English language, fr_FR for the French langue etc, The translation is taken for the both, Front and Back, but you can specify your translation just for the back if you want like this:

"Bestsellers","Translation here",module,Magento_Backend

In Magento 1 we have the possibility to set a specific translation file for front or admin via xml config :

<frontend>
    <translate>
        <modules>
            <translations>
                <files>
                    <default>Translations.csv</default>
                </files>
            </translations>
        </modules>
    </translate>
</frontend>

<adminhtml>
    <translate>
        <modules>
            <translations>
                <files>
                    <default>Translations.csv</default>
                </files>
            </translations>
        </modules>
    </translate>
</adminhtml>

Note That you can also enable the Translate Inline via Admin : Stores -> Configuration -> Developper -> Translate Inline

This Translate Inline will saved in database translation table and it have the highest priority translation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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