I want to know how to update some translation through Magento 2.1.9 REST API.
For example, when I add a configurable product in the cart thanks to the Magento 2.1.9 REST API, if the user do not select an option, the default error message response is You need to choose options for your item.
Which is translated here vendor/magento/module-configurable-product/i18n/en_US.csv:30
And trigger here : vendor/magento/module-configurable-product/Model/Product/Type/Configurable.php:1095
I want to update the default translation, but I do not find a way to solve it, I try :
- I added the updated translation in my theme :
app/design/frontend/Vendor/theme/i18n/en_US.csv:5
but it seems that the theme is not load in the API mode - I forced the current area and store with
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
Without success.
I do not find any resource how to translate through API area.
I prefer keep all the translation in Magento and not delegate this to the frontend application.
All ideas are appreciated.
EDIT:
I just found a workaround.
You need to emulate the correct store with the frontend area, and then reload the translation data :
// Emulate store frontend
$storeId = $this->storeManager->getStore()->getId();
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
$this->translator->loadData(null, true);
echo __('your text to translate');
$this->appEmulation->stopEnvironmentEmulation();
But it is just a workaround for custom API where you manage the result, not for native Magento API.
Let me know if there is a proper way to manage this.
Does language packages can solve my problem ?
en
is store code, yourdomain.com/en/rest/V1/your/url