Skip to content

Commit 64be712

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'remotes/api/MAGETWO-43739-Translations-Are-Not-Picked-From-The-Right-Module' into API-M11-Bug-Fixes
2 parents c154938 + 98630b1 commit 64be712

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/internal/Magento/Framework/Test/Unit/TranslateTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ public function setUp()
6868
$this->resource = $this->getMock('\Magento\Framework\Translate\ResourceInterface', [], [], '', false);
6969
$this->locale = $this->getMock('\Magento\Framework\Locale\ResolverInterface', [], [], '', false);
7070
$this->appState = $this->getMock('\Magento\Framework\App\State', [], [], '', false);
71-
$this->request = $this->getMock('\Magento\Framework\App\RequestInterface', [], [], '', false);
71+
$this->request = $this->getMockForAbstractClass(
72+
'\Magento\Framework\App\RequestInterface',
73+
[],
74+
'',
75+
false,
76+
false,
77+
true,
78+
['getParam', 'getControllerModule']
79+
);
7280
$this->csvParser = $this->getMock('\Magento\Framework\File\Csv', [], [], '', false);
7381
$this->packDictionary = $this->getMock('\Magento\Framework\App\Language\Dictionary', [], [], '', false);
7482
$this->directory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false);

lib/internal/Magento/Framework/Translate.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ protected function setConfig($config)
204204
if (!isset($this->_config['theme'])) {
205205
$this->_config['theme'] = $this->_viewDesign->getDesignTheme()->getId();
206206
}
207+
if (!isset($this->_config['module'])) {
208+
$this->_config['module'] = $this->getControllerModuleName();
209+
}
207210
return $this;
208211
}
209212

@@ -232,14 +235,39 @@ protected function getConfig($key)
232235
return null;
233236
}
234237

238+
/**
239+
* Retrieve name of the current module
240+
* @return mixed
241+
*/
242+
protected function getControllerModuleName()
243+
{
244+
return $this->request->getControllerModule();
245+
}
246+
235247
/**
236248
* Load data from module translation files
237249
*
238250
* @return $this
239251
*/
240252
protected function _loadModuleTranslation()
241253
{
242-
foreach ($this->_moduleList->getNames() as $module) {
254+
$currentModule = $this->getControllerModuleName();
255+
$allModulesExceptCurrent = array_diff($this->_moduleList->getNames(), [$currentModule]);
256+
257+
$this->loadModuleTranslationByModulesList($allModulesExceptCurrent);
258+
$this->loadModuleTranslationByModulesList([$currentModule]);
259+
return $this;
260+
}
261+
262+
/**
263+
* Load data from module translation files by list of modules
264+
*
265+
* @param array $modules
266+
* @return $this
267+
*/
268+
protected function loadModuleTranslationByModulesList(array $modules)
269+
{
270+
foreach ($modules as $module) {
243271
$moduleFilePath = $this->_getModuleTranslationFile($module, $this->getLocale());
244272
$this->_addData($this->_getFileData($moduleFilePath));
245273
}
@@ -428,6 +456,9 @@ protected function getCacheId($forceReload = false)
428456
if (isset($this->_config['theme'])) {
429457
$this->_cacheId .= '_' . $this->_config['theme'];
430458
}
459+
if (isset($this->_config['module'])) {
460+
$this->_cacheId .= '_' . $this->_config['module'];
461+
}
431462
}
432463
return $this->_cacheId;
433464
}

0 commit comments

Comments
 (0)