From 0e4c83dd19d5baf7f4c67731f884502752f0090c Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Tue, 20 Nov 2018 12:23:33 +0000 Subject: [PATCH] Remove language.i18.backend setting; make each templating system use its own i18n backend. Twig will always use gettext, legacy will use legacy. Twig does not work with legacy so new ui would break if you would not also set this option. Instead, just switch the system in use based on the usenewui config variable. --- config-templates/config.php | 11 ----------- lib/SimpleSAML/Locale/Localization.php | 2 +- lib/SimpleSAML/XHTML/Template.php | 3 ++- templates/sandbox.twig | 11 ----------- tests/lib/SimpleSAML/Locale/LocalizationTest.php | 4 ++-- tests/modules/core/lib/ControllerTest.php | 2 +- tests/www/TemplateTest.php | 2 +- 7 files changed, 7 insertions(+), 28 deletions(-) diff --git a/config-templates/config.php b/config-templates/config.php index 1fa9d3b40..09117a875 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -727,17 +727,6 @@ $config = [ 'language.cookie.httponly' => false, 'language.cookie.lifetime' => (60 * 60 * 24 * 900), - /* - * Which i18n backend to use. - * - * "SimpleSAMLphp" is the home made system, valid for 1.x. - * For 2.x, only "gettext/gettext" will be possible. - * - * Home-made templates will always use "SimpleSAMLphp". - * To use twig (where avaliable), select "gettext/gettext". - */ - 'language.i18n.backend' => 'SimpleSAMLphp', - /** * Custom getLanguage function called from SimpleSAML\Locale\Language::getLanguage(). * Function should return language code of one of the available languages or NULL. diff --git a/lib/SimpleSAML/Locale/Localization.php b/lib/SimpleSAML/Locale/Localization.php index 9a4543d37..66427da45 100644 --- a/lib/SimpleSAML/Locale/Localization.php +++ b/lib/SimpleSAML/Locale/Localization.php @@ -96,7 +96,7 @@ class Localization $this->localeDir = $this->configuration->resolvePath('locales'); $this->language = new Language($configuration); $this->langcode = $this->language->getPosixLanguage($this->language->getLanguage()); - $this->i18nBackend = $this->configuration->getString('language.i18n.backend', self::SSP_I18N_BACKEND); + $this->i18nBackend = ($this->configuration->getBoolean('usenewui', false) ? self::GETTEXT_I18N_BACKEND : self::SSP_I18N_BACKEND); $this->setupL10N(); } diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 042f06830..903076ff6 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -12,6 +12,7 @@ namespace SimpleSAML\XHTML; use JaimePerez\TwigConfigurableI18n\Twig\Environment as Twig_Environment; use JaimePerez\TwigConfigurableI18n\Twig\Extensions\Extension\I18n as Twig_Extensions_Extension_I18n; use Symfony\Component\HttpFoundation\Response; +use SimpleSAML\Locale\Localization; class Template extends Response { @@ -265,7 +266,7 @@ class Template extends Response // initialize some basic context $langParam = $this->configuration->getString('language.parameter.name', 'language'); $twig->addGlobal('languageParameterName', $langParam); - $twig->addGlobal('localeBackend', $this->configuration->getString('language.i18n.backend', 'SimpleSAMLphp')); + $twig->addGlobal('localeBackend', $this->useNewUI ? Localization::GETTEXT_I18N_BACKEND : Localization::SSP_I18N_BACKEND); $twig->addGlobal('currentLanguage', $this->translator->getLanguage()->getLanguage()); $twig->addGlobal('isRTL', false); // language RTL configuration if ($this->translator->getLanguage()->isLanguageRTL()) { diff --git a/templates/sandbox.twig b/templates/sandbox.twig index 316c855cf..1ff8134fd 100644 --- a/templates/sandbox.twig +++ b/templates/sandbox.twig @@ -15,17 +15,6 @@ </p> <h2>Localization</h2> {% set variable = 'Hello, Untranslated World!' %} - <p>SimpleSAMLphp lets you choose which translation backend to choose, thanks to the - <code>language.i18n.backend</code> configuration option. Two possible values are supported there: - </p> - <ul> - <li><code>SimpleSAMLphp</code>: to keep using the old SimpleSAMLphp translation system. This is the - default, and will disappear as an option in SimpleSAMLphp 2.0.</li> - <li><code>gettext/gettext</code>: to use a <em>gettext</em> implementation written entirely in PHP, allowing - you to use any locale, no matter if they are installed on the system or not.</li> - </ul> - <p>Note that <code>gettext/gettext</code> <strong>will become the default</strong> in SimpleSAMLphp 2.0. - Currently, you are using the following backend: <code>{{ localeBackend }}</code>.</p> <p>This page is written in english only, but the examples used here are translated to several languages. The current language is <strong>{{ currentLanguage }}</strong>. Change to other languages to see the examples change.</p> <h4>Usage examples</h4> diff --git a/tests/lib/SimpleSAML/Locale/LocalizationTest.php b/tests/lib/SimpleSAML/Locale/LocalizationTest.php index cc58f1ebe..ceeb823fb 100644 --- a/tests/lib/SimpleSAML/Locale/LocalizationTest.php +++ b/tests/lib/SimpleSAML/Locale/LocalizationTest.php @@ -22,7 +22,7 @@ class LocalizationTest extends TestCase { // The constructor should activate the default domain $c = Configuration::loadFromArray( - ['language.i18n.backend' => 'SimpleSAMLphp'] + ['usenewui' => false] ); $l = new Localization($c); $this->assertTrue($l->isI18NBackendDefault()); @@ -35,7 +35,7 @@ class LocalizationTest extends TestCase public function testAddDomain() { $c = Configuration::loadFromArray( - ['language.i18n.backend' => 'gettext/gettext'] + ['usenewui' => true] ); $l = new Localization($c); $newDomain = 'test'; diff --git a/tests/modules/core/lib/ControllerTest.php b/tests/modules/core/lib/ControllerTest.php index ff7c959f8..9f2edea91 100644 --- a/tests/modules/core/lib/ControllerTest.php +++ b/tests/modules/core/lib/ControllerTest.php @@ -61,7 +61,7 @@ class ControllerTest extends ClearStateTestCase [ 'baseurlpath' => 'https://example.org/simplesaml', 'module.enable' => ['exampleauth' => true], - 'language.i18n.backend' => Localization::GETTEXT_I18N_BACKEND, + 'usenewui' => true, ], '[ARRAY]', 'simplesaml' diff --git a/tests/www/TemplateTest.php b/tests/www/TemplateTest.php index 06dfe1080..2e9e3a4f4 100644 --- a/tests/www/TemplateTest.php +++ b/tests/www/TemplateTest.php @@ -19,7 +19,7 @@ class TemplateTest extends TestCase public function testSyntax() { $config = Configuration::loadFromArray([ - 'language.i18n.backend' => 'gettext/gettext', + 'usenewui' => true, 'module.enable' => array_fill_keys(Module::getModules(), true), ]); Configuration::setPreLoadedConfig($config); -- GitLab