Skip to content

Commit 8b51cf8

Browse files
committed
PWA-806: Localize emails sent through GraphQL application
1 parent f0598bb commit 8b51cf8

File tree

4 files changed

+27
-70
lines changed

4 files changed

+27
-70
lines changed

app/code/Magento/GraphQl/Plugin/TranslationLoader.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

app/code/Magento/GraphQl/etc/graphql/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@
4141
</argument>
4242
</arguments>
4343
</type>
44-
<type name="Magento\Framework\Phrase">
45-
<plugin name="graphQlLocalizationPhrasePlugin" type="Magento\GraphQl\Plugin\TranslationLoader" />
46-
</type>
4744
</config>

app/code/Magento/StoreGraphQl/Controller/HttpHeaderProcessor/StoreProcessor.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
namespace Magento\StoreGraphQl\Controller\HttpHeaderProcessor;
99

10+
use Magento\Framework\App\AreaInterface;
11+
use Magento\Framework\App\AreaList;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\App\State;
1014
use Magento\GraphQl\Controller\HttpHeaderProcessorInterface;
1115
use Magento\Store\Model\StoreManagerInterface;
1216
use Magento\Framework\App\Http\Context as HttpContext;
@@ -32,19 +36,35 @@ class StoreProcessor implements HttpHeaderProcessorInterface
3236
*/
3337
private $storeCookieManager;
3438

39+
/**
40+
* @var AreaList
41+
*/
42+
private $areaList;
43+
44+
/**
45+
* @var State
46+
*/
47+
private $appState;
48+
3549
/**
3650
* @param StoreManagerInterface $storeManager
3751
* @param HttpContext $httpContext
3852
* @param StoreCookieManagerInterface $storeCookieManager
53+
* @param AreaList $areaList
54+
* @param State $appState
3955
*/
4056
public function __construct(
4157
StoreManagerInterface $storeManager,
4258
HttpContext $httpContext,
43-
StoreCookieManagerInterface $storeCookieManager
59+
StoreCookieManagerInterface $storeCookieManager,
60+
AreaList $areaList = null,
61+
State $appState = null
4462
) {
4563
$this->storeManager = $storeManager;
4664
$this->httpContext = $httpContext;
4765
$this->storeCookieManager = $storeCookieManager;
66+
$this->areaList = $areaList ?? ObjectManager::getInstance()->get(AreaList::class);
67+
$this->appState = $appState ?? ObjectManager::getInstance()->get(State::class);
4868
}
4969

5070
/**
@@ -67,6 +87,10 @@ public function processHeaderValue(string $headerValue) : void
6787
$this->storeManager->setCurrentStore($storeCode);
6888
$this->updateContext($storeCode);
6989
}
90+
91+
// Load translations for the app
92+
$area = $this->areaList->getArea($this->appState->getAreaCode());
93+
$area->load(AreaInterface::PART_TRANSLATE);
7094
}
7195

7296
/**

lib/internal/Magento/Framework/Phrase/__.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

9-
use Magento\Framework\App\ObjectManager;
10-
use Magento\Framework\Phrase;
11-
128
/**
139
* Create value-object \Magento\Framework\Phrase
1410
*
1511
* @SuppressWarnings(PHPMD.ShortMethodName)
1612
* phpcs:disable Squiz.Functions.GlobalFunction
1713
* @param array $argc
18-
* @return Phrase
14+
* @return \Magento\Framework\Phrase
1915
*/
2016
function __(...$argc)
2117
{
@@ -24,11 +20,5 @@ function __(...$argc)
2420
$argc = $argc[0];
2521
}
2622

27-
return ObjectManager::getInstance()->create(
28-
Phrase::class,
29-
[
30-
'text' => $text,
31-
'arguments' => $argc
32-
]
33-
);
23+
return new \Magento\Framework\Phrase($text, $argc);
3424
}

0 commit comments

Comments
 (0)