Skip to content

Commit caa2fe8

Browse files
committed
#17833: Child theme does not inherit translations from parent theme
(cherry picked from commit 388fb45)
1 parent 42eebbb commit caa2fe8

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

@@ -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,73 @@ protected function _getModuleTranslationFile($moduleName, $locale)
377383
return $file;
378384
}
379385

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

0 commit comments

Comments
 (0)