|
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,73 @@ 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 $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 | + |
380 | 444 | /**
|
381 | 445 | * Retrieve translation file for theme
|
382 | 446 | *
|
383 | 447 | * @param string $locale
|
384 | 448 | * @return string
|
| 449 | + * |
| 450 | + * @deprecated |
| 451 | + * |
| 452 | + * @see \Magento\Framework\Translate::getThemeTranslationFilesList |
385 | 453 | */
|
386 | 454 | protected function _getThemeTranslationFile($locale)
|
387 | 455 | {
|
|
0 commit comments