X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FDefinition%2FTranslator%2FDefinitionTranslator.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FDefinition%2FTranslator%2FDefinitionTranslator.php;h=3192a3d8e8c45cb62fc90eb9361b49e479cb5b4e;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Behat/Definition/Translator/DefinitionTranslator.php b/vendor/behat/behat/src/Behat/Behat/Definition/Translator/DefinitionTranslator.php new file mode 100644 index 000000000..3192a3d8e --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Definition/Translator/DefinitionTranslator.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Definition\Translator; + +use Behat\Behat\Definition\Definition; +use Behat\Testwork\Suite\Suite; +use Symfony\Component\Translation\TranslatorInterface; + +/** + * Translates definitions using translator component. + * + * @author Konstantin Kudryashov + */ +final class DefinitionTranslator +{ + /** + * @var TranslatorInterface + */ + private $translator; + + /** + * Initialises definition translator. + * + * @param TranslatorInterface $translator + */ + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + /** + * Attempts to translate definition using translator and produce translated one on success. + * + * @param Suite $suite + * @param Definition $definition + * @param null|string $language + * + * @return Definition|TranslatedDefinition + */ + public function translateDefinition(Suite $suite, Definition $definition, $language = null) + { + $assetsId = $suite->getName(); + $pattern = $definition->getPattern(); + + $translatedPattern = $this->translator->trans($pattern, array(), $assetsId, $language); + if ($pattern != $translatedPattern) { + return new TranslatedDefinition($definition, $translatedPattern, $language); + } + + return $definition; + } + + public function getLocale() + { + return $this->translator->getLocale(); + } +}