diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php index ded7eeb7c43ba07f7c7a504bcb50e60a51dd1ff6..8cc20565102c2ea48986ab7bd4599b5b22447d56 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 fb47b808bfcbce6f943c4bc9d205421b880c528b..02201a01cfc44ade9b2fc0ae0ddcd770b43a2513 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 1480ee0cbbd87e337c35717a06233e27a61fd5ed..c75c53143050dec1ebc6a78d81b1405578170bd4 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 d7c089ee285c07c9ba0fb15ddda4411b12abeea0..35b740c4a06d88f9f19d699f4c998cb55f3e6d8d 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 4c82ae861198016fc9ace6fa2c535c3b1574b64b..316c855cfba98e398a8237ed4dc77567505efdf5 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>