|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
6 | 7 |
|
7 | 8 | namespace Magento\Framework;
|
8 | 9 |
|
@@ -339,16 +340,21 @@ protected function _addData($data)
|
339 | 340 | }
|
340 | 341 |
|
341 | 342 | /**
|
342 |
| - * Load current theme translation |
| 343 | + * Load current theme translation according to fallback |
343 | 344 | *
|
344 | 345 | * @return $this
|
345 | 346 | */
|
346 | 347 | protected function _loadThemeTranslation()
|
347 | 348 | {
|
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 | + } |
351 | 356 | }
|
| 357 | + |
352 | 358 | return $this;
|
353 | 359 | }
|
354 | 360 |
|
@@ -389,11 +395,73 @@ protected function _getModuleTranslationFile($moduleName, $locale)
|
389 | 395 | return $file;
|
390 | 396 | }
|
391 | 397 |
|
| 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 | + |
392 | 456 | /**
|
393 | 457 | * Retrieve translation file for theme
|
394 | 458 | *
|
395 | 459 | * @param string $locale
|
396 | 460 | * @return string
|
| 461 | + * |
| 462 | + * @deprecated |
| 463 | + * |
| 464 | + * @see \Magento\Framework\Translate::getThemeTranslationFilesList |
397 | 465 | */
|
398 | 466 | protected function _getThemeTranslationFile($locale)
|
399 | 467 | {
|
|
0 commit comments