Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Translator / DefinitionTranslator.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Definition\Translator;
12
13 use Behat\Behat\Definition\Definition;
14 use Behat\Testwork\Suite\Suite;
15 use Symfony\Component\Translation\TranslatorInterface;
16
17 /**
18  * Translates definitions using translator component.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class DefinitionTranslator
23 {
24     /**
25      * @var TranslatorInterface
26      */
27     private $translator;
28
29     /**
30      * Initialises definition translator.
31      *
32      * @param TranslatorInterface $translator
33      */
34     public function __construct(TranslatorInterface $translator)
35     {
36         $this->translator = $translator;
37     }
38
39     /**
40      * Attempts to translate definition using translator and produce translated one on success.
41      *
42      * @param Suite       $suite
43      * @param Definition  $definition
44      * @param null|string $language
45      *
46      * @return Definition|TranslatedDefinition
47      */
48     public function translateDefinition(Suite $suite, Definition $definition, $language = null)
49     {
50         $assetsId = $suite->getName();
51         $pattern = $definition->getPattern();
52
53         $translatedPattern = $this->translator->trans($pattern, array(), $assetsId, $language);
54         if ($pattern != $translatedPattern) {
55             return new TranslatedDefinition($definition, $translatedPattern, $language);
56         }
57
58         return $definition;
59     }
60
61     public function getLocale()
62     {
63         return $this->translator->getLocale();
64     }
65 }