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

Make PHP's native gettext implementation work with twig.

parent dca36184
No related branches found
No related tags found
No related merge requests found
...@@ -28,9 +28,19 @@ class Localization ...@@ -28,9 +28,19 @@ class Localization
const DEFAULT_DOMAIN = 'ssp'; const DEFAULT_DOMAIN = 'ssp';
/** /**
* Default 1i18n backend * Old internationalization backend included in SimpleSAMLphp.
*/ */
const DEFAULT_I18NBACKEND = 'SimpleSAMLphp'; const OLD_I18N_BACKEND = 'SimpleSAMLphp';
/**
* PHP's native internationalization backend (gettext).
*/
const NATIVE_I18_NBACKEND = 'ext-intl';
/**
* An internationalization backend implemented purely in PHP.
*/
const PHP_I18N_BACKEND = 'gettext/gettext';
/* /*
* The default locale directory * The default locale directory
...@@ -159,7 +169,7 @@ class Localization ...@@ -159,7 +169,7 @@ class Localization
*/ */
public function isI18NBackendDefault() public function isI18NBackendDefault()
{ {
if ($this->i18nBackend === $this::DEFAULT_I18NBACKEND) { if ($this->i18nBackend === $this::OLD_I18N_BACKEND) {
return true; return true;
} }
return false; return false;
...@@ -171,14 +181,20 @@ class Localization ...@@ -171,14 +181,20 @@ class Localization
*/ */
private function setupL10N() private function setupL10N()
{ {
// use old system switch ($this->i18nBackend) {
if ($this->isI18NBackendDefault()) { 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);
} }
/** /**
...@@ -197,9 +213,15 @@ class Localization ...@@ -197,9 +213,15 @@ class Localization
*/ */
public function activateDomain($domain) public function activateDomain($domain)
{ {
\SimpleSAML\Logger::debug("Localization: activate domain"); if ($this->i18nBackend === 'ext-intl') {
$this->loadGettextGettextFromPO($domain); bindtextdomain($domain, $this->localeDir);
$this->currentDomain = $domain; bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
} else {
\SimpleSAML\Logger::debug("Localization: activate domain");
$this->loadGettextGettextFromPO($domain);
$this->currentDomain = $domain;
}
} }
......
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