Loading .travis.yml +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ before_script: - composer require "symfony/process:^3.4" --no-interaction --working-dir=${TRAVIS_BUILD_DIR}/../drupal-8/drupal script: - export SYMFONY_DEPRECATIONS_HELPER=disabled - drupal-ti script after_script: Loading src/Extractor/TwigExtractor.php +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface { * * @return \Drupal\potion\MessageCatalogue * Catalogue of extracted translations messages. * * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ protected function extractFromTemplate($template) { /** @var \Drupal\potion\Twig\NodeVisitor\TranslationNodeVisitor $visitor */ Loading @@ -78,7 +81,7 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface { * @param string $directory * Directory to dig in. * @param bool $recursive * Enable or disable scan with recusrsion. * Enable or disable scan with recursion. * * @return \Iterator|SplFileInfo[] * An iterator. Loading src/Twig/NodeVisitor/TranslationNodeVisitor.php +14 −8 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\potion\Twig\NodeVisitor; use Drupal\Core\Template\TwigNodeTrans; use Twig\NodeVisitor\AbstractNodeVisitor; use Drupal\potion\MessageCatalogue; use Twig\Node\CheckToStringNode; /** * Extracts translation messages from twig. Loading Loading @@ -172,7 +173,7 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { } /** * Extracts the text for complexe form of "trans" tag. * Extracts the text for complex form of "trans" tag. * * @param \Twig_Node $body * The node to compile. Loading @@ -180,6 +181,8 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { * @return string * The translations strings. * * @throws \Twig_Error_Syntax * * @see \Drupal\Core\Template\TwigNodeTrans::compileString */ protected function compileString(\Twig_Node $body) { Loading @@ -196,6 +199,9 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { $n = $n->getNode('node'); } if ($n instanceof CheckToStringNode) { $n = $n->getNode('expr'); } $args = $n; // Support TwigExtension->renderVar() function in chain. Loading @@ -205,25 +211,25 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { // Detect if a token implements one of the filters reserved for // modifying the prefix of a token. The default prefix used for // translations is "@". This escapes the printed token and makes // them // safe for templates. // translations is "@". This escapes the printed token and makes them // safe for templates. // @see TwigExtension::getFilters() $argPrefix = '@'; while ($args instanceof \Twig_Node_Expression_Filter) { switch ($args->getNode('filter')->getAttribute( 'value' )) { switch ($args->getNode('filter')->getAttribute('value')) { case 'placeholder': $argPrefix = '%'; break; } $args = $args->getNode('node'); } if ($args instanceof CheckToStringNode) { $args = $args->getNode('expr'); } if ($args instanceof \Twig_Node_Expression_GetAttr) { $argName = []; // Assemble a valid argument name by walking through expression. $argName[] = $args->getNode('attribute') ->getAttribute('value'); $argName[] = $args->getNode('attribute')->getAttribute('value'); while ($args->hasNode('node')) { $args = $args->getNode('node'); if ($args instanceof \Twig_Node_Expression_Name) { Loading tests/src/Kernel/TranslationsExportTest.php +3 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ class TranslationsExportTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExport::exportFromDatabase */ public function testExportInvalidLangcode() { $this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->translationExport->exportFromDatabase('ru'); } Loading tests/src/Kernel/TranslationsExtractorTest.php +6 −3 Original line number Diff line number Diff line Loading @@ -104,7 +104,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExtractor::extract */ public function testExtractSourceNotFound() { $this->setExpectedException(PotionException::class, "No such file or directory temporary://not-found"); $this->expectException(PotionException::class); $this->expectExceptionMessage("No such file or directory temporary://not-found"); $this->translationExtractor->extract('fr', 'temporary://not-found', TRUE); } Loading @@ -117,7 +118,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { $this->fileSystem->prepareDirectory($dest, FILE_CREATE_DIRECTORY); @chmod($dest, 0000); $this->setExpectedException(PotionException::class, "The path temporary://not-readable is not readable."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The path temporary://not-readable is not readable."); $this->translationExtractor->extract('fr', 'temporary://not-readable', TRUE); } Loading @@ -125,7 +127,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExtractor::extract */ public function testExtractInvalidLangcode() { $this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->translationExtractor->extract('ru', $this->extractionPath, TRUE); } Loading Loading
.travis.yml +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ before_script: - composer require "symfony/process:^3.4" --no-interaction --working-dir=${TRAVIS_BUILD_DIR}/../drupal-8/drupal script: - export SYMFONY_DEPRECATIONS_HELPER=disabled - drupal-ti script after_script: Loading
src/Extractor/TwigExtractor.php +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface { * * @return \Drupal\potion\MessageCatalogue * Catalogue of extracted translations messages. * * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ protected function extractFromTemplate($template) { /** @var \Drupal\potion\Twig\NodeVisitor\TranslationNodeVisitor $visitor */ Loading @@ -78,7 +81,7 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface { * @param string $directory * Directory to dig in. * @param bool $recursive * Enable or disable scan with recusrsion. * Enable or disable scan with recursion. * * @return \Iterator|SplFileInfo[] * An iterator. Loading
src/Twig/NodeVisitor/TranslationNodeVisitor.php +14 −8 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\potion\Twig\NodeVisitor; use Drupal\Core\Template\TwigNodeTrans; use Twig\NodeVisitor\AbstractNodeVisitor; use Drupal\potion\MessageCatalogue; use Twig\Node\CheckToStringNode; /** * Extracts translation messages from twig. Loading Loading @@ -172,7 +173,7 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { } /** * Extracts the text for complexe form of "trans" tag. * Extracts the text for complex form of "trans" tag. * * @param \Twig_Node $body * The node to compile. Loading @@ -180,6 +181,8 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { * @return string * The translations strings. * * @throws \Twig_Error_Syntax * * @see \Drupal\Core\Template\TwigNodeTrans::compileString */ protected function compileString(\Twig_Node $body) { Loading @@ -196,6 +199,9 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { $n = $n->getNode('node'); } if ($n instanceof CheckToStringNode) { $n = $n->getNode('expr'); } $args = $n; // Support TwigExtension->renderVar() function in chain. Loading @@ -205,25 +211,25 @@ class TranslationNodeVisitor extends AbstractNodeVisitor { // Detect if a token implements one of the filters reserved for // modifying the prefix of a token. The default prefix used for // translations is "@". This escapes the printed token and makes // them // safe for templates. // translations is "@". This escapes the printed token and makes them // safe for templates. // @see TwigExtension::getFilters() $argPrefix = '@'; while ($args instanceof \Twig_Node_Expression_Filter) { switch ($args->getNode('filter')->getAttribute( 'value' )) { switch ($args->getNode('filter')->getAttribute('value')) { case 'placeholder': $argPrefix = '%'; break; } $args = $args->getNode('node'); } if ($args instanceof CheckToStringNode) { $args = $args->getNode('expr'); } if ($args instanceof \Twig_Node_Expression_GetAttr) { $argName = []; // Assemble a valid argument name by walking through expression. $argName[] = $args->getNode('attribute') ->getAttribute('value'); $argName[] = $args->getNode('attribute')->getAttribute('value'); while ($args->hasNode('node')) { $args = $args->getNode('node'); if ($args instanceof \Twig_Node_Expression_Name) { Loading
tests/src/Kernel/TranslationsExportTest.php +3 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ class TranslationsExportTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExport::exportFromDatabase */ public function testExportInvalidLangcode() { $this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->translationExport->exportFromDatabase('ru'); } Loading
tests/src/Kernel/TranslationsExtractorTest.php +6 −3 Original line number Diff line number Diff line Loading @@ -104,7 +104,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExtractor::extract */ public function testExtractSourceNotFound() { $this->setExpectedException(PotionException::class, "No such file or directory temporary://not-found"); $this->expectException(PotionException::class); $this->expectExceptionMessage("No such file or directory temporary://not-found"); $this->translationExtractor->extract('fr', 'temporary://not-found', TRUE); } Loading @@ -117,7 +118,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { $this->fileSystem->prepareDirectory($dest, FILE_CREATE_DIRECTORY); @chmod($dest, 0000); $this->setExpectedException(PotionException::class, "The path temporary://not-readable is not readable."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The path temporary://not-readable is not readable."); $this->translationExtractor->extract('fr', 'temporary://not-readable', TRUE); } Loading @@ -125,7 +127,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase { * @covers \Drupal\potion\TranslationsExtractor::extract */ public function testExtractInvalidLangcode() { $this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->expectException(PotionException::class); $this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it."); $this->translationExtractor->extract('ru', $this->extractionPath, TRUE); } Loading