Config.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Translation\Model\Js;
  7. use Magento\Framework\Translate\Js\Config as FrameworkJsConfig;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. /**
  10. * Js Translation config
  11. */
  12. class Config extends FrameworkJsConfig
  13. {
  14. /**
  15. * Both translation strategies are disabled
  16. */
  17. const NO_TRANSLATION = 'none';
  18. /**
  19. * Strategy when all js files are translated while publishing
  20. */
  21. const EMBEDDED_STRATEGY = 'embedded';
  22. /**
  23. * Strategy when dictionary is generated for dynamic translation
  24. */
  25. const DICTIONARY_STRATEGY = 'dictionary';
  26. /**
  27. * Configuration path to translation strategy
  28. */
  29. const XML_PATH_STRATEGY = 'dev/js/translate_strategy';
  30. /**
  31. * Dictionary file name
  32. */
  33. const DICTIONARY_FILE_NAME = 'js-translation.json';
  34. /**
  35. * Core store config
  36. *
  37. * @var ScopeConfigInterface
  38. */
  39. protected $scopeConfig;
  40. /**
  41. * Patterns to match strings for translation
  42. *
  43. * @var string[]
  44. */
  45. protected $patterns;
  46. /**
  47. * @param ScopeConfigInterface $scopeConfig
  48. * @param string[] $patterns
  49. */
  50. public function __construct(ScopeConfigInterface $scopeConfig, array $patterns)
  51. {
  52. $this->scopeConfig = $scopeConfig;
  53. $this->patterns = $patterns;
  54. parent::__construct(
  55. $this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::DICTIONARY_STRATEGY,
  56. self::DICTIONARY_FILE_NAME
  57. );
  58. }
  59. /**
  60. * Is Embedded Strategy selected
  61. *
  62. * @return bool
  63. */
  64. public function isEmbeddedStrategy()
  65. {
  66. return ($this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::EMBEDDED_STRATEGY);
  67. }
  68. /**
  69. * Is Dictionary Strategy selected
  70. *
  71. * @return bool
  72. */
  73. public function dictionaryEnabled()
  74. {
  75. return ($this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::DICTIONARY_STRATEGY);
  76. }
  77. /**
  78. * Retrieve translation patterns
  79. *
  80. * @return string[]
  81. */
  82. public function getPatterns()
  83. {
  84. return $this->patterns;
  85. }
  86. }