The locale of a store is defined in the store config with the path 'general/locale/code'
. To get the value of the correct store, one has to use the store ID of the order.
Here's an example how to achieve this in a helper:
namespace Acme\MyModule\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Store\Model\ScopeInterface;
class Data extends AbstractHelper
{
public function getOrderStoreLanguage(OrderInterface $order): ?string
{
$locale = $this->scopeConfig->getValue(
'general/locale/code',
ScopeInterface::SCOPE_STORE,
$order->getStoreId()
);
if (!$locale) {
return null;
}
return $locale;
}
}
If you need that in another custom class, you have to inject the scope config into the constructor.
namespace Acme\MyModule\Observer;
use Magento\Framework\App\Config\ScopeConfigInterface;
class CustomObserver
{
private ScopeConfigInterface $scopeConfig;
public function __construct(ScopeConfigInterface $scopeConfig) {
$this->scopeConfig = $scopeConfig;
}
}
Then you can get the locale of the store in the same way as in the example above.
I hope this helps other's, too.