diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php index 412fc2ac9fca5d2ef57d97c1e83e1e6ab7a71be6..b0ea40120a22b3b2ba676293ffae5c0bf9b2104e 100644 --- a/lib/SimpleSAML/Locale/Language.php +++ b/lib/SimpleSAML/Locale/Language.php @@ -115,6 +115,17 @@ class Language 'eu' => 'Euskara', // Basque ); + /** + * A mapping of SSP languages to locales + * + * @var array + */ + private $languagePosixMapping = array( + 'no' => 'nb_NO', + 'en' => 'en_US', + 'nn' => 'nn_NO', + ); + /** * Constructor @@ -138,6 +149,20 @@ class Language } + /* + * Rename to non-idiosyncratic language code + * + * @param string $language Language code for the language to rename, if neccesary. + */ + public function getPosixLanguage($language) + { + if (isset($this->languagePosixMapping[$language])) { + return $this->languagePosixMapping[$language]; + } + return $language; + } + + /** * This method will set a cookie for the user's browser to remember what language was selected. * diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index b2fa78042f2d2654b553c04d87a68b63315a5a6a..cc76a3e94184eae5a1447affd797fcc0df497276 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -24,6 +24,13 @@ class SimpleSAML_XHTML_Template */ private $translator; + /** + * The localization backend + * + * @var \SimpleSAML\Locale\Localization + */ + private $localization; + /** * The configuration to use in this template. * @@ -65,6 +72,8 @@ class SimpleSAML_XHTML_Template // TODO: do not remove the slash from the beginning, change the templates instead! $this->data['baseurlpath'] = ltrim($this->configuration->getBasePath(), '/'); $this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary); + $this->localization = new \SimpleSAML\Locale\Localization($configuration); + $this->useTwig = $this->setupTwig(); $this->twig = $this->setupTwig(); } @@ -146,7 +155,12 @@ class SimpleSAML_XHTML_Template return null; } - return new \Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => $auto_reload)); + $twig = new \Twig_Environment($loader, array('cache' => $cache, 'auto_reload' => $auto_reload)); + if ($this->localization->i18nBackend == 'twig.i18n') { + $this->localization->activateDomain('ssp'); + $twig->addExtension(new \Twig_Extensions_Extension_I18n()); + } + return $twig; } /* diff --git a/templates/sandbox.twig b/templates/sandbox.twig index 0d42e5e167194712301a8e4a369de1f20c06aad2..97f0b64fdd52646ab138b18212d713a7f25165f5 100644 --- a/templates/sandbox.twig +++ b/templates/sandbox.twig @@ -2,5 +2,7 @@ {% block content %} <p>This page exists as a sandbox to play with twig without affecting anything else. The template is in ./templates.</p> <p>{{ sometext }}</p> + <p>Original: Hello, Untranslated World!</p> + <p>Translated: {% trans 'Hello, Untranslated World!' %}</p> <p>Current locale set: {{ currentLanguage }}</p> {% endblock content %}