|
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 |
|
@@ -327,16 +328,21 @@ protected function _addData($data) |
327 | 328 | } |
328 | 329 |
|
329 | 330 | /** |
330 | | - * Load current theme translation |
| 331 | + * Load current theme translation according to fallback |
331 | 332 | * |
332 | 333 | * @return $this |
333 | 334 | */ |
334 | 335 | protected function _loadThemeTranslation() |
335 | 336 | { |
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 | + } |
339 | 344 | } |
| 345 | + |
340 | 346 | return $this; |
341 | 347 | } |
342 | 348 |
|
@@ -377,11 +383,74 @@ protected function _getModuleTranslationFile($moduleName, $locale) |
377 | 383 | return $file; |
378 | 384 | } |
379 | 385 |
|
| 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 | + |
380 | 445 | /** |
381 | 446 | * Retrieve translation file for theme |
382 | 447 | * |
383 | 448 | * @param string $locale |
384 | 449 | * @return string |
| 450 | + * |
| 451 | + * @deprecated |
| 452 | + * |
| 453 | + * @see \Magento\Framework\Translate::getThemeTranslationFilesList |
385 | 454 | */ |
386 | 455 | protected function _getThemeTranslationFile($locale) |
387 | 456 | { |
|
0 commit comments