From bcd084121e27b772bf44483a8eec88659810b26a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no>
Date: Tue, 4 Oct 2016 16:44:38 +0200
Subject: [PATCH] bugfix: Start using the twig-i18n wrapper.

Since the class names were prepended with "\", the original extension was used, instead of our own wrapper. This fixes that issue, and sets the two new methods in SimpleSAML\Locale\Translate as the functions to use to replace the calls to gettext() and ngettext(). Support for the old translation system is still missing for twig templates.
---
 lib/SimpleSAML/XHTML/Template.php | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index 2f6204876..ee84beff0 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -165,21 +165,21 @@ class SimpleSAML_XHTML_Template
             return false;
         }
 
-        $twig = new \Twig_Environment($loader,
-            array('cache' => $cache, 'auto_reload' => $auto_reload,
-                'translation_function' => '__',
-                'translation_function_plural' => 'n__',
-            )
+        $options = array(
+            'cache' => $cache,
+            'auto_reload' => $auto_reload,
+            'translation_function' => 'gettext',
+            'translation_function_plural' => 'ngettext',
         );
+
         // set up translation
-        if ($this->localization->i18nBackend == 'twig.gettextgettext') {
-            /* if something like pull request #166 is ever merged with
-             * twig.extensions.i18n, use the line below:
-             * $twig->addExtension(new \Twig_Extensions_Extension_I18n('__', 'n__'));
-             * instead of the two lines after this comment
-             */
-            $twig->addExtension(new \Twig_Extensions_Extension_I18n());
-        }
+        if ($this->localization->i18nBackend === 'gettext/gettext') {
+            $options['translation_function'] = array('\SimpleSAML\Locale\Translate', 'translateSingular');
+            $options['translation_function_plural'] = array('\SimpleSAML\Locale\Translate', 'translatePlural');
+        } // TODO: add a branch for the old SimpleSAMLphp backend
+
+        $twig = new Twig_Environment($loader, $options);
+        $twig->addExtension(new Twig_Extensions_Extension_I18n());
         return $twig;
     }
 
-- 
GitLab