Config.php 2.18 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Translation\Model\Js;

use Magento\Framework\Translate\Js\Config as FrameworkJsConfig;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
 * Js Translation config
 */
class Config extends FrameworkJsConfig
{
    /**
     * Both translation strategies are disabled
     */
    const NO_TRANSLATION = 'none';

    /**
     * Strategy when all js files are translated while publishing
     */
    const EMBEDDED_STRATEGY = 'embedded';

    /**
     * Strategy when dictionary is generated for dynamic translation
     */
    const DICTIONARY_STRATEGY = 'dictionary';

    /**
     * Configuration path to translation strategy
     */
    const XML_PATH_STRATEGY = 'dev/js/translate_strategy';

    /**
     * Dictionary file name
     */
    const DICTIONARY_FILE_NAME = 'js-translation.json';

    /**
     * Core store config
     *
     * @var ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * Patterns to match strings for translation
     *
     * @var string[]
     */
    protected $patterns;

    /**
     * @param ScopeConfigInterface $scopeConfig
     * @param string[] $patterns
     */
    public function __construct(ScopeConfigInterface $scopeConfig, array $patterns)
    {
        $this->scopeConfig = $scopeConfig;
        $this->patterns = $patterns;
        parent::__construct(
            $this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::DICTIONARY_STRATEGY,
            self::DICTIONARY_FILE_NAME
        );
    }

    /**
     * Is Embedded Strategy selected
     *
     * @return bool
     */
    public function isEmbeddedStrategy()
    {
        return ($this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::EMBEDDED_STRATEGY);
    }

    /**
     * Is Dictionary Strategy selected
     *
     * @return bool
     */
    public function dictionaryEnabled()
    {
        return ($this->scopeConfig->getValue(self::XML_PATH_STRATEGY) == self::DICTIONARY_STRATEGY);
    }

    /**
     * Retrieve translation patterns
     *
     * @return string[]
     */
    public function getPatterns()
    {
        return $this->patterns;
    }
}