From 8c265d2c96ac903e6c7526ef2c7199cf8651cc93 Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Fri, 22 Oct 2021 09:27:26 +0200 Subject: [PATCH 1/3] Support old and new twig --- potx.inc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/potx.inc b/potx.inc index cb009d4..2c3bc39 100644 --- a/potx.inc +++ b/potx.inc @@ -30,8 +30,10 @@ spl_autoload_register(function($c){ }); use Drupal\Component\Gettext\PoItem; +use Drupal\Core\Template\Loader\FilesystemLoader; use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Exception\ParseException; +use Twig\Source; /** * The current Drupal major API verion. @@ -1798,10 +1800,30 @@ function _potx_parse_js_string($string) { * Parse a Twig template for translatables. Drupal 8+. */ function _potx_parse_twig_file($code, $file, $save_callback) { - $twig_lexer = new Twig_Lexer(new Twig_Environment()); + $is_twig_1 = TRUE; + $twig_lexer = NULL; + try { + $twig_lexer = new Twig_Lexer(new Twig_Environment()); + } + catch (ArgumentCountError $e) { + // Probably means we need to use the syntax for twig 2. + $is_twig_1 = FALSE; + } + if (!$twig_lexer) { + $module_handler = \Drupal::moduleHandler(); + $theme_handler = \Drupal::service('theme_handler'); + $loader = new FilesystemLoader($file, $module_handler, $theme_handler); + $twig_lexer = new Twig_Lexer(new Twig_Environment($loader)); + } try { - $stream = $twig_lexer->tokenize($code, $file); + if ($is_twig_1) { + $stream = $twig_lexer->tokenize($code, $file); + } + else { + $source = new Source($code, $file); + $stream = $twig_lexer->tokenize($source); + } } catch(Twig_Error_Syntax $e) { potx_status('error', t("Twig parsing error on file @path: @error", array( '@path' => $file, From 9c9a8936ec744c04b1580cf2565df21ff677dffb Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Fri, 22 Oct 2021 09:27:35 +0200 Subject: [PATCH 2/3] Support being installed on drupal 9 --- potx.info.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/potx.info.yml b/potx.info.yml index 4670bd9..86531c0 100644 --- a/potx.info.yml +++ b/potx.info.yml @@ -1,6 +1,7 @@ name: Translation template extractor description: Provides a web interface and an API to extract translatable text from the sources of installed components. core: 8.x +core_version_requirement: ^8 || ^9 package: Multilingual version: 8.x-1.x-dev dependencies: From 49f2a9097cbbccc04b038b344578c17ac693f72e Mon Sep 17 00:00:00 2001 From: Eirik Stanghelle Morland Date: Wed, 20 Sep 2023 12:32:34 +0200 Subject: [PATCH 3/3] Update potx.info.yml --- potx.info.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/potx.info.yml b/potx.info.yml index 86531c0..9627644 100644 --- a/potx.info.yml +++ b/potx.info.yml @@ -1,7 +1,6 @@ name: Translation template extractor description: Provides a web interface and an API to extract translatable text from the sources of installed components. -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Multilingual version: 8.x-1.x-dev dependencies: