From 8b7e9cbe874483ee1f0cace8f01028ac88fda361 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no>
Date: Tue, 11 Oct 2016 15:35:42 +0200
Subject: [PATCH] Give up trying native gettext to work, not worth the trouble.
---
lib/SimpleSAML/Locale/Language.php | 1 -
lib/SimpleSAML/Locale/Localization.php | 45 ++++++++------------------
lib/SimpleSAML/Locale/Translate.php | 32 ++----------------
lib/SimpleSAML/XHTML/Template.php | 8 ++---
templates/sandbox.twig | 4 +--
5 files changed, 21 insertions(+), 69 deletions(-)
diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php
index ded7eeb7c..8cc205651 100644
--- a/lib/SimpleSAML/Locale/Language.php
+++ b/lib/SimpleSAML/Locale/Language.php
@@ -125,7 +125,6 @@ class Language
*/
private $languagePosixMapping = array(
'no' => 'nb_NO',
- 'en' => 'en_US',
'nn' => 'nn_NO',
);
diff --git a/lib/SimpleSAML/Locale/Localization.php b/lib/SimpleSAML/Locale/Localization.php
index fb47b808b..02201a01c 100644
--- a/lib/SimpleSAML/Locale/Localization.php
+++ b/lib/SimpleSAML/Locale/Localization.php
@@ -30,17 +30,12 @@ class Localization
/**
* Old internationalization backend included in SimpleSAMLphp.
*/
- const OLD_I18N_BACKEND = 'SimpleSAMLphp';
-
- /**
- * PHP's native internationalization backend (gettext).
- */
- const NATIVE_I18_NBACKEND = 'ext-intl';
+ const SSP_I18N_BACKEND = 'SimpleSAMLphp';
/**
* An internationalization backend implemented purely in PHP.
*/
- const PHP_I18N_BACKEND = 'gettext/gettext';
+ const GETTEXT_I18N_BACKEND = 'gettext/gettext';
/*
* The default locale directory
@@ -74,7 +69,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', null);
+ $this->i18nBackend = $this->configuration->getString('language.i18n.backend', self::SSP_I18N_BACKEND);
$this->setupL10N();
}
@@ -169,7 +164,7 @@ class Localization
*/
public function isI18NBackendDefault()
{
- if ($this->i18nBackend === $this::OLD_I18N_BACKEND) {
+ if ($this->i18nBackend === $this::SSP_I18N_BACKEND) {
return true;
}
return false;
@@ -181,20 +176,14 @@ class Localization
*/
private function setupL10N()
{
- switch ($this->i18nBackend) {
- case self::OLD_I18N_BACKEND: // use old system
- \SimpleSAML\Logger::debug("Localization: using old system");
- return;
- case self::NATIVE_I18_NBACKEND:
- putenv('LC_ALL='.$this->langcode);
- putenv('LANGUAGE='.$this->langcode);
- setlocale(LC_ALL, $this->langcode);
- // continue to add the domain
- default:
- // setup default domain
- $this->addDomain($this->localeDir, self::DEFAULT_DOMAIN);
- $this->activateDomain(self::DEFAULT_DOMAIN);
+ if ($this->i18nBackend === self::SSP_I18N_BACKEND) {
+ \SimpleSAML\Logger::debug("Localization: using old system");
+ return;
}
+
+ // setup default domain
+ $this->addDomain($this->localeDir, self::DEFAULT_DOMAIN);
+ $this->activateDomain(self::DEFAULT_DOMAIN);
}
/**
@@ -213,15 +202,9 @@ class Localization
*/
public function activateDomain($domain)
{
- if ($this->i18nBackend === 'ext-intl') {
- bindtextdomain($domain, $this->localeDir);
- bind_textdomain_codeset($domain, 'UTF-8');
- textdomain($domain);
- } else {
- \SimpleSAML\Logger::debug("Localization: activate domain");
- $this->loadGettextGettextFromPO($domain);
- $this->currentDomain = $domain;
- }
+ \SimpleSAML\Logger::debug("Localization: activate domain");
+ $this->loadGettextGettextFromPO($domain);
+ $this->currentDomain = $domain;
}
diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php
index 1480ee0cb..c75c53143 100644
--- a/lib/SimpleSAML/Locale/Translate.php
+++ b/lib/SimpleSAML/Locale/Translate.php
@@ -469,7 +469,7 @@ class Translate
}
- public static function translateSingularPHPGettext($original)
+ public static function translateSingularGettext($original)
{
$text = \Gettext\BaseTranslator::$current->gettext($original);
@@ -483,7 +483,7 @@ class Translate
}
- public static function translatePluralPHPGettext($original, $plural, $value)
+ public static function translatePluralGettext($original, $plural, $value)
{
$text = \Gettext\BaseTranslator::$current->ngettext($original, $plural, $value);
@@ -495,32 +495,4 @@ class Translate
return strtr($text, is_array($args[0]) ? $args[0] : $args);
}
-
-
- public static function translateSingularNativeGettext($original)
- {
- $text = gettext($original);
-
- if (func_num_args() === 1) {
- return $text;
- }
-
- $args = array_slice(func_get_args(), 1);
-
- return strtr($text, is_array($args[0]) ? $args[0] : $args);
- }
-
-
- public static function translatePluralNativeGettext($original, $plural, $value)
- {
- $text = ngettext($original, $plural, $value);
-
- if (func_num_args() === 3) {
- return $text;
- }
-
- $args = array_slice(func_get_args(), 3);
-
- return strtr($text, is_array($args[0]) ? $args[0] : $args);
- }
}
diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index d7c089ee2..35b740c4a 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -173,11 +173,11 @@ class SimpleSAML_XHTML_Template
);
// set up translation
- if ($this->localization->i18nBackend === 'gettext/gettext') {
- $options['translation_function'] = array('\SimpleSAML\Locale\Translate', 'translateSingularPHPGettext');
+ if ($this->localization->i18nBackend === \SimpleSAML\Locale\Localization::GETTEXT_I18N_BACKEND) {
+ $options['translation_function'] = array('\SimpleSAML\Locale\Translate', 'translateSingularGettext');
$options['translation_function_plural'] = array(
'\SimpleSAML\Locale\Translate',
- 'translatePluralPHPGettext'
+ 'translatePluralGettext'
);
} // TODO: add a branch for the old SimpleSAMLphp backend
@@ -289,7 +289,7 @@ class SimpleSAML_XHTML_Template
*/
private function twigDefaultContext()
{
- $this->data['localeBackend'] = $this->configuration->getString('language.i18n.backend', 'ssp');
+ $this->data['localeBackend'] = $this->configuration->getString('language.i18n.backend', 'SimpleSAMLphp');
$this->data['currentLanguage'] = $this->translator->getLanguage()->getLanguage();
// show language bar by default
if (!isset($this->data['hideLanguageBar'])) {
diff --git a/templates/sandbox.twig b/templates/sandbox.twig
index 4c82ae861..316c855cf 100644
--- a/templates/sandbox.twig
+++ b/templates/sandbox.twig
@@ -16,13 +16,11 @@
<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. Three possible values are supported there:
+ <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>ext-intl</code>: to use PHP's native <em>gettext</em> implementation. Bear in mind that using this
- will require you to install the locales of the languages you are planning to use, system-wide.</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>
--
GitLab