Skip to content
Snippets Groups Projects
Commit e8c7f1c5 authored by Hanne Moa's avatar Hanne Moa
Browse files

Hook up new localization with twig.i18n

parent 9243d9b3
No related branches found
No related tags found
No related merge requests found
...@@ -115,6 +115,17 @@ class Language ...@@ -115,6 +115,17 @@ class Language
'eu' => 'Euskara', // Basque '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 * Constructor
...@@ -138,6 +149,20 @@ class Language ...@@ -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. * This method will set a cookie for the user's browser to remember what language was selected.
* *
......
...@@ -24,6 +24,13 @@ class SimpleSAML_XHTML_Template ...@@ -24,6 +24,13 @@ class SimpleSAML_XHTML_Template
*/ */
private $translator; private $translator;
/**
* The localization backend
*
* @var \SimpleSAML\Locale\Localization
*/
private $localization;
/** /**
* The configuration to use in this template. * The configuration to use in this template.
* *
...@@ -65,6 +72,8 @@ class SimpleSAML_XHTML_Template ...@@ -65,6 +72,8 @@ class SimpleSAML_XHTML_Template
// TODO: do not remove the slash from the beginning, change the templates instead! // TODO: do not remove the slash from the beginning, change the templates instead!
$this->data['baseurlpath'] = ltrim($this->configuration->getBasePath(), '/'); $this->data['baseurlpath'] = ltrim($this->configuration->getBasePath(), '/');
$this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary); $this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary);
$this->localization = new \SimpleSAML\Locale\Localization($configuration);
$this->useTwig = $this->setupTwig();
$this->twig = $this->setupTwig(); $this->twig = $this->setupTwig();
} }
...@@ -146,7 +155,12 @@ class SimpleSAML_XHTML_Template ...@@ -146,7 +155,12 @@ class SimpleSAML_XHTML_Template
return null; 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;
} }
/* /*
......
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
{% block content %} {% block content %}
<p>This page exists as a sandbox to play with twig without affecting anything else. The template is in ./templates.</p> <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>{{ sometext }}</p>
<p>Original: Hello, Untranslated World!</p>
<p>Translated: {% trans 'Hello, Untranslated World!' %}</p>
<p>Current locale set: {{ currentLanguage }}</p> <p>Current locale set: {{ currentLanguage }}</p>
{% endblock content %} {% endblock content %}
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