Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 73 additions & 4 deletions lib/internal/Magento/Framework/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework;

Expand Down Expand Up @@ -339,16 +340,21 @@ protected function _addData($data)
}

/**
* Load current theme translation
* Load current theme translation according to fallback
*
* @return $this
*/
protected function _loadThemeTranslation()
{
$file = $this->_getThemeTranslationFile($this->getLocale());
if ($file) {
$this->_addData($this->_getFileData($file));
$themeFiles = $this->getThemeTranslationFilesList($this->getLocale());

/** @var string $file */
foreach ($themeFiles as $file) {
if ($file) {
$this->_addData($this->_getFileData($file));
}
}

return $this;
}

Expand Down Expand Up @@ -389,11 +395,74 @@ protected function _getModuleTranslationFile($moduleName, $locale)
return $file;
}

/**
* Get theme translation locale file name
*
* @param string $locale
* @param array $config
* @return string|null
*/
private function getThemeTranslationFileName(string $locale, array $config): ?string
{
$fileName = $this->_viewFileSystem->getLocaleFileName(
'i18n' . '/' . $locale . '.csv',
$config
);

return $fileName ? $fileName : null;
}

/**
* Get parent themes for the current theme in fallback order
*
* @return array
*/
private function getParentThemesList(): array
{
$themes = [];

$parentTheme = $this->_viewDesign->getDesignTheme()->getParentTheme();
while ($parentTheme) {
$themes[] = $parentTheme;
$parentTheme = $parentTheme->getParentTheme();
}
$themes = array_reverse($themes);

return $themes;
}

/**
* Retrieve translation files for themes according to fallback
*
* @param string $locale
*
* @return array
*/
private function getThemeTranslationFilesList($locale): array
{
$translationFiles = [];

/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
foreach ($this->getParentThemesList() as $theme) {
$config = $this->_config;
$config['theme'] = $theme->getCode();
$translationFiles[] = $this->getThemeTranslationFileName($locale, $config);
}

$translationFiles[] = $this->getThemeTranslationFileName($locale, $this->_config);

return $translationFiles;
}

/**
* Retrieve translation file for theme
*
* @param string $locale
* @return string
*
* @deprecated
*
* @see \Magento\Framework\Translate::getThemeTranslationFilesList
*/
protected function _getThemeTranslationFile($locale)
{
Expand Down