Skip to content

Commit 38d14a0

Browse files
authored
ENGCOM-3527: [2.2 develop] [backport #19018] [issue #17833] child theme does not inherit translations from parent theme #19023
2 parents a427b30 + 6051858 commit 38d14a0

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

lib/internal/Magento/Framework/Translate.php

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

78
namespace Magento\Framework;
89

@@ -327,16 +328,21 @@ protected function _addData($data)
327328
}
328329

329330
/**
330-
* Load current theme translation
331+
* Load current theme translation according to fallback
331332
*
332333
* @return $this
333334
*/
334335
protected function _loadThemeTranslation()
335336
{
336-
$file = $this->_getThemeTranslationFile($this->getLocale());
337-
if ($file) {
338-
$this->_addData($this->_getFileData($file));
337+
$themeFiles = $this->getThemeTranslationFilesList($this->getLocale());
338+
339+
/** @var string $file */
340+
foreach ($themeFiles as $file) {
341+
if ($file) {
342+
$this->_addData($this->_getFileData($file));
343+
}
339344
}
345+
340346
return $this;
341347
}
342348

@@ -377,11 +383,74 @@ protected function _getModuleTranslationFile($moduleName, $locale)
377383
return $file;
378384
}
379385

386+
/**
387+
* Get theme translation locale file name
388+
*
389+
* @param string|null $locale
390+
* @param array $config
391+
* @return string|null
392+
*/
393+
private function getThemeTranslationFileName($locale, array $config)
394+
{
395+
$fileName = $this->_viewFileSystem->getLocaleFileName(
396+
'i18n' . '/' . $locale . '.csv',
397+
$config
398+
);
399+
400+
return $fileName ? $fileName : null;
401+
}
402+
403+
/**
404+
* Get parent themes for the current theme in fallback order
405+
*
406+
* @return array
407+
*/
408+
private function getParentThemesList(): array
409+
{
410+
$themes = [];
411+
412+
$parentTheme = $this->_viewDesign->getDesignTheme()->getParentTheme();
413+
while ($parentTheme) {
414+
$themes[] = $parentTheme;
415+
$parentTheme = $parentTheme->getParentTheme();
416+
}
417+
$themes = array_reverse($themes);
418+
419+
return $themes;
420+
}
421+
422+
/**
423+
* Retrieve translation files for themes according to fallback
424+
*
425+
* @param string $locale
426+
*
427+
* @return array
428+
*/
429+
private function getThemeTranslationFilesList($locale): array
430+
{
431+
$translationFiles = [];
432+
433+
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
434+
foreach ($this->getParentThemesList() as $theme) {
435+
$config = $this->_config;
436+
$config['theme'] = $theme->getCode();
437+
$translationFiles[] = $this->getThemeTranslationFileName($locale, $config);
438+
}
439+
440+
$translationFiles[] = $this->getThemeTranslationFileName($locale, $this->_config);
441+
442+
return $translationFiles;
443+
}
444+
380445
/**
381446
* Retrieve translation file for theme
382447
*
383448
* @param string $locale
384449
* @return string
450+
*
451+
* @deprecated
452+
*
453+
* @see \Magento\Framework\Translate::getThemeTranslationFilesList
385454
*/
386455
protected function _getThemeTranslationFile($locale)
387456
{

0 commit comments

Comments
 (0)