DeployTranslationsDictionary.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Service;
  7. use Magento\Framework\App\State;
  8. use Magento\Framework\Translate\Js\Config as JsTranslationConfig;
  9. use Psr\Log\LoggerInterface;
  10. /**
  11. * Deploy translation dictionaries service
  12. */
  13. class DeployTranslationsDictionary
  14. {
  15. /**
  16. * @var JsTranslationConfig
  17. */
  18. private $jsTranslationConfig;
  19. /**
  20. * @var DeployStaticFile
  21. */
  22. private $deployStaticFile;
  23. /**
  24. * @var State
  25. */
  26. private $state;
  27. /**
  28. * @var LoggerInterface
  29. */
  30. private $logger;
  31. /**
  32. * @param JsTranslationConfig $jsTranslationConfig
  33. * @param DeployStaticFile $deployStaticFile
  34. * @param State $state
  35. * @param LoggerInterface $logger
  36. */
  37. public function __construct(
  38. JsTranslationConfig $jsTranslationConfig,
  39. DeployStaticFile $deployStaticFile,
  40. State $state,
  41. LoggerInterface $logger
  42. ) {
  43. $this->jsTranslationConfig = $jsTranslationConfig;
  44. $this->deployStaticFile = $deployStaticFile;
  45. $this->state = $state;
  46. $this->logger = $logger;
  47. }
  48. /**
  49. * @param string $area
  50. * @param string $theme
  51. * @param string $locale
  52. * @return void
  53. */
  54. public function deploy($area, $theme, $locale)
  55. {
  56. try {
  57. $this->state->emulateAreaCode($area, function () use ($area, $theme, $locale) {
  58. $this->deployStaticFile->deployFile(
  59. $this->jsTranslationConfig->getDictionaryFileName(),
  60. [
  61. 'fileName' => $this->jsTranslationConfig->getDictionaryFileName(),
  62. 'area' => $area,
  63. 'theme' => $theme,
  64. 'locale' => $locale
  65. ]
  66. );
  67. });
  68. } catch (\Exception $e) {
  69. $this->logger->error($e->getMessage());
  70. }
  71. }
  72. }