Skip to content
Snippets Groups Projects
Commit 8b7e9cbe authored by Jaime Pérez's avatar Jaime Pérez
Browse files

Give up trying native gettext to work, not worth the trouble.

parent fecdd267
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,6 @@ class Language ...@@ -125,7 +125,6 @@ class Language
*/ */
private $languagePosixMapping = array( private $languagePosixMapping = array(
'no' => 'nb_NO', 'no' => 'nb_NO',
'en' => 'en_US',
'nn' => 'nn_NO', 'nn' => 'nn_NO',
); );
......
...@@ -30,17 +30,12 @@ class Localization ...@@ -30,17 +30,12 @@ class Localization
/** /**
* Old internationalization backend included in SimpleSAMLphp. * Old internationalization backend included in SimpleSAMLphp.
*/ */
const OLD_I18N_BACKEND = 'SimpleSAMLphp'; const SSP_I18N_BACKEND = 'SimpleSAMLphp';
/**
* PHP's native internationalization backend (gettext).
*/
const NATIVE_I18_NBACKEND = 'ext-intl';
/** /**
* An internationalization backend implemented purely in PHP. * An internationalization backend implemented purely in PHP.
*/ */
const PHP_I18N_BACKEND = 'gettext/gettext'; const GETTEXT_I18N_BACKEND = 'gettext/gettext';
/* /*
* The default locale directory * The default locale directory
...@@ -74,7 +69,7 @@ class Localization ...@@ -74,7 +69,7 @@ class Localization
$this->localeDir = $this->configuration->resolvePath('locales'); $this->localeDir = $this->configuration->resolvePath('locales');
$this->language = new Language($configuration); $this->language = new Language($configuration);
$this->langcode = $this->language->getPosixLanguage($this->language->getLanguage()); $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(); $this->setupL10N();
} }
...@@ -169,7 +164,7 @@ class Localization ...@@ -169,7 +164,7 @@ class Localization
*/ */
public function isI18NBackendDefault() public function isI18NBackendDefault()
{ {
if ($this->i18nBackend === $this::OLD_I18N_BACKEND) { if ($this->i18nBackend === $this::SSP_I18N_BACKEND) {
return true; return true;
} }
return false; return false;
...@@ -181,20 +176,14 @@ class Localization ...@@ -181,20 +176,14 @@ class Localization
*/ */
private function setupL10N() private function setupL10N()
{ {
switch ($this->i18nBackend) { if ($this->i18nBackend === self::SSP_I18N_BACKEND) {
case self::OLD_I18N_BACKEND: // use old system \SimpleSAML\Logger::debug("Localization: using old system");
\SimpleSAML\Logger::debug("Localization: using old system"); return;
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);
} }
// setup default domain
$this->addDomain($this->localeDir, self::DEFAULT_DOMAIN);
$this->activateDomain(self::DEFAULT_DOMAIN);
} }
/** /**
...@@ -213,15 +202,9 @@ class Localization ...@@ -213,15 +202,9 @@ class Localization
*/ */
public function activateDomain($domain) public function activateDomain($domain)
{ {
if ($this->i18nBackend === 'ext-intl') { \SimpleSAML\Logger::debug("Localization: activate domain");
bindtextdomain($domain, $this->localeDir); $this->loadGettextGettextFromPO($domain);
bind_textdomain_codeset($domain, 'UTF-8'); $this->currentDomain = $domain;
textdomain($domain);
} else {
\SimpleSAML\Logger::debug("Localization: activate domain");
$this->loadGettextGettextFromPO($domain);
$this->currentDomain = $domain;
}
} }
......
...@@ -469,7 +469,7 @@ class Translate ...@@ -469,7 +469,7 @@ class Translate
} }
public static function translateSingularPHPGettext($original) public static function translateSingularGettext($original)
{ {
$text = \Gettext\BaseTranslator::$current->gettext($original); $text = \Gettext\BaseTranslator::$current->gettext($original);
...@@ -483,7 +483,7 @@ class Translate ...@@ -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); $text = \Gettext\BaseTranslator::$current->ngettext($original, $plural, $value);
...@@ -495,32 +495,4 @@ class Translate ...@@ -495,32 +495,4 @@ class Translate
return strtr($text, is_array($args[0]) ? $args[0] : $args); 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);
}
} }
...@@ -173,11 +173,11 @@ class SimpleSAML_XHTML_Template ...@@ -173,11 +173,11 @@ class SimpleSAML_XHTML_Template
); );
// set up translation // set up translation
if ($this->localization->i18nBackend === 'gettext/gettext') { if ($this->localization->i18nBackend === \SimpleSAML\Locale\Localization::GETTEXT_I18N_BACKEND) {
$options['translation_function'] = array('\SimpleSAML\Locale\Translate', 'translateSingularPHPGettext'); $options['translation_function'] = array('\SimpleSAML\Locale\Translate', 'translateSingularGettext');
$options['translation_function_plural'] = array( $options['translation_function_plural'] = array(
'\SimpleSAML\Locale\Translate', '\SimpleSAML\Locale\Translate',
'translatePluralPHPGettext' 'translatePluralGettext'
); );
} // TODO: add a branch for the old SimpleSAMLphp backend } // TODO: add a branch for the old SimpleSAMLphp backend
...@@ -289,7 +289,7 @@ class SimpleSAML_XHTML_Template ...@@ -289,7 +289,7 @@ class SimpleSAML_XHTML_Template
*/ */
private function twigDefaultContext() 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(); $this->data['currentLanguage'] = $this->translator->getLanguage()->getLanguage();
// show language bar by default // show language bar by default
if (!isset($this->data['hideLanguageBar'])) { if (!isset($this->data['hideLanguageBar'])) {
......
...@@ -16,13 +16,11 @@ ...@@ -16,13 +16,11 @@
<h2>Localization</h2> <h2>Localization</h2>
{% set variable = 'Hello, Untranslated World!' %} {% set variable = 'Hello, Untranslated World!' %}
<p>SimpleSAMLphp lets you choose which translation backend to choose, thanks to the <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> </p>
<ul> <ul>
<li><code>SimpleSAMLphp</code>: to keep using the old SimpleSAMLphp translation system. This is the <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> 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 <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> you to use any locale, no matter if they are installed on the system or not.</li>
</ul> </ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment