Plugin.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Translate\Locale\Resolver;
  7. /**
  8. * Magento translate abstract adapter
  9. */
  10. class Plugin
  11. {
  12. /**
  13. * @var \Magento\Framework\TranslateInterface
  14. */
  15. protected $_translate;
  16. /**
  17. * @param \Magento\Framework\TranslateInterface $translate
  18. */
  19. public function __construct(\Magento\Framework\TranslateInterface $translate)
  20. {
  21. $this->_translate = $translate;
  22. }
  23. /**
  24. * @param \Magento\Framework\Locale\ResolverInterface $subject
  25. * @param string|null $localeCode
  26. * @return void
  27. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  28. */
  29. public function afterEmulate(\Magento\Framework\Locale\ResolverInterface $subject, $localeCode)
  30. {
  31. $this->_init($localeCode);
  32. }
  33. /**
  34. * @param \Magento\Framework\Locale\ResolverInterface $subject
  35. * @param string|null $localeCode
  36. * @return void
  37. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  38. */
  39. public function afterRevert(\Magento\Framework\Locale\ResolverInterface $subject, $localeCode)
  40. {
  41. $this->_init($localeCode);
  42. }
  43. /**
  44. * @param string|null $localeCode
  45. * @return void
  46. */
  47. protected function _init($localeCode)
  48. {
  49. if ($localeCode !== null) {
  50. $this->_translate->setLocale($localeCode)
  51. ->loadData();
  52. }
  53. }
  54. }