Skip to content

Commit 388fb45

Browse files
committed
#17833: Child theme does not inherit translations from parent theme
1 parent c515b40 commit 388fb45

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

lib/internal/Magento/Framework/Translate.php

Lines changed: 72 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

@@ -339,16 +340,21 @@ protected function _addData($data)
339340
}
340341

341342
/**
342-
* Load current theme translation
343+
* Load current theme translation according to fallback
343344
*
344345
* @return $this
345346
*/
346347
protected function _loadThemeTranslation()
347348
{
348-
$file = $this->_getThemeTranslationFile($this->getLocale());
349-
if ($file) {
350-
$this->_addData($this->_getFileData($file));
349+
$themeFiles = $this->getThemeTranslationFilesList($this->getLocale());
350+
351+
/** @var string $file */
352+
foreach ($themeFiles as $file) {
353+
if ($file) {
354+
$this->_addData($this->_getFileData($file));
355+
}
351356
}
357+
352358
return $this;
353359
}
354360

@@ -389,11 +395,73 @@ protected function _getModuleTranslationFile($moduleName, $locale)
389395
return $file;
390396
}
391397

398+
/**
399+
* Get theme translation locale file name
400+
*
401+
* @param string $locale
402+
* @param array $config
403+
* @return string
404+
*/
405+
private function getThemeTranslationFileName(string $locale, array $config): string
406+
{
407+
return $this->_viewFileSystem->getLocaleFileName(
408+
'i18n' . '/' . $locale . '.csv',
409+
$config
410+
);
411+
}
412+
413+
/**
414+
* Get parent themes for the current theme in fallback order
415+
*
416+
* @return array
417+
*/
418+
private function getParentThemesList(): array
419+
{
420+
$themes = [];
421+
422+
$parentTheme = $this->_viewDesign->getDesignTheme()->getParentTheme();
423+
while($parentTheme) {
424+
$themes[] = $parentTheme;
425+
$parentTheme = $parentTheme->getParentTheme();
426+
}
427+
$themes = array_reverse($themes);
428+
429+
return $themes;
430+
}
431+
432+
/**
433+
* Retrieve translation files for themes according to fallback
434+
*
435+
* @param string $locale
436+
*
437+
* @return array
438+
*/
439+
private function getThemeTranslationFilesList($locale): array
440+
{
441+
$translationFiles = [];
442+
443+
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
444+
foreach ($this->getParentThemesList() as $theme) {
445+
$config = $this->_config;
446+
$config['theme'] = $theme->getCode();
447+
$translationFiles[] = $this->getThemeTranslationFileName($locale, $config);
448+
}
449+
450+
$translationFiles[] = $this->getThemeTranslationFileName($locale, $this->_config);
451+
452+
return $translationFiles;
453+
}
454+
455+
392456
/**
393457
* Retrieve translation file for theme
394458
*
395459
* @param string $locale
396460
* @return string
461+
*
462+
* @deprecated
463+
*
464+
* @see \Magento\Framework\Translate::getThemeTranslationFilesList
397465
*/
398466
protected function _getThemeTranslationFile($locale)
399467
{

0 commit comments

Comments
 (0)