4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Definition\Translator;
13 use Behat\Behat\Definition\Definition;
14 use Behat\Testwork\Suite\Suite;
15 use Symfony\Component\Translation\TranslatorInterface;
18 * Translates definitions using translator component.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class DefinitionTranslator
25 * @var TranslatorInterface
30 * Initialises definition translator.
32 * @param TranslatorInterface $translator
34 public function __construct(TranslatorInterface $translator)
36 $this->translator = $translator;
40 * Attempts to translate definition using translator and produce translated one on success.
43 * @param Definition $definition
44 * @param null|string $language
46 * @return Definition|TranslatedDefinition
48 public function translateDefinition(Suite $suite, Definition $definition, $language = null)
50 $assetsId = $suite->getName();
51 $pattern = $definition->getPattern();
53 $translatedPattern = $this->translator->trans($pattern, array(), $assetsId, $language);
54 if ($pattern != $translatedPattern) {
55 return new TranslatedDefinition($definition, $translatedPattern, $language);
61 public function getLocale()
63 return $this->translator->getLocale();