Skip to content
Snippets Groups Projects
Commit 4e5c779d authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Remove calls to getPrefferedTranslation

parent 78ba8206
No related branches found
No related tags found
No related merge requests found
...@@ -143,45 +143,6 @@ class Translate ...@@ -143,45 +143,6 @@ class Translate
} }
/**
* Retrieve the preferred translation of a given text.
*
* @param array $translations The translations, as an associative array with language => text mappings.
*
* @return string The preferred translation.
*
* @throws \Exception If there's no suitable translation.
*/
public function getPreferredTranslation(array $translations): string
{
// look up translation of tag in the selected language
$selected_language = $this->language->getLanguage();
if (array_key_exists($selected_language, $translations)) {
return $translations[$selected_language];
}
// look up translation of tag in the default language
$default_language = $this->language->getDefaultLanguage();
if (array_key_exists($default_language, $translations)) {
return $translations[$default_language];
}
// check for english translation
if (array_key_exists('en', $translations)) {
return $translations['en'];
}
// pick the first translation available
if (count($translations) > 0) {
$languages = array_keys($translations);
return $translations[$languages[0]];
}
// we don't have anything to return
throw new \Exception('Nothing to return from translation.');
}
/** /**
* Translate the name of an attribute. * Translate the name of an attribute.
* *
......
...@@ -180,10 +180,7 @@ class Test ...@@ -180,10 +180,7 @@ class Test
"NameId" => [$nameId->getValue()], "NameId" => [$nameId->getValue()],
]; ];
if ($nameId->getFormat() !== null) { if ($nameId->getFormat() !== null) {
$format = $translator->getPreferredTranslation( $list['Format'] = [$nameId->getFormat()];
$translator->getTag('{status:subject_format}') ?? ['en' => 'Format']
);
$list[$format] = [$nameId->getFormat()];
} }
if ($nameId->getNameQualifier() !== null) { if ($nameId->getNameQualifier() !== null) {
$list['NameQualifier'] = [$nameId->getNameQualifier()]; $list['NameQualifier'] = [$nameId->getNameQualifier()];
...@@ -327,10 +324,7 @@ class Test ...@@ -327,10 +324,7 @@ class Test
'NameID' => [$nameID->getValue()], 'NameID' => [$nameID->getValue()],
]; ];
if ($nameID->getFormat() !== null) { if ($nameID->getFormat() !== null) {
$format = $t->getPreferredTranslation( $eptid['Format'] = [$nameID->getFormat()];
$t->getTag('{status:subject_format}') ?? ['en' => 'Format']
);
$eptid[$format] = [$nameID->getFormat()];
} }
if ($nameID->getNameQualifier() !== null) { if ($nameID->getNameQualifier() !== null) {
$eptid['NameQualifier'] = [$nameID->getNameQualifier()]; $eptid['NameQualifier'] = [$nameID->getNameQualifier()];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<h2>{{ 'Invalid Identity Provider'|trans }}</h2> <h2>{{ 'Invalid Identity Provider'|trans }}</h2>
<p>{{ 'You already have a valid session with an identity provider (<em>%IDP%</em>) that is not accepted by <em>%SP%</em>. Would you like to log out from your existing session and log in again with another identity provider?'|trans({"%IDP%": idp_name, "%SP%": sp_name}, "app")|raw</p> <p>{{ 'You already have a valid session with an identity provider (<em>%IDP%</em>) that is not accepted by <em>%SP%</em>. Would you like to log out from your existing session and log in again with another identity provider?'|trans({"%IDP%": idp_name|translateFromArray|default(idp_entityid), "%SP%": sp_name|translateFromArray|default(sp_entityid)}, "app")|raw</p>
<form method="post" action="?"> <form method="post" action="?">
<input type="hidden" name="AuthState" value="{{ AuthState|escape('html') }}" /> <input type="hidden" name="AuthState" value="{{ AuthState|escape('html') }}" />
<input type="submit" name="continue" value="{{ 'Yes, continue'|trans }}" /> <input type="submit" name="continue" value="{{ 'Yes, continue'|trans }}" />
......
...@@ -56,21 +56,19 @@ $idpmdcfg = $state['saml:sp:IdPMetadata']; ...@@ -56,21 +56,19 @@ $idpmdcfg = $state['saml:sp:IdPMetadata'];
/** @var \SimpleSAML\Configuration $idpmdcfg */ /** @var \SimpleSAML\Configuration $idpmdcfg */
$idpmd = $idpmdcfg->toArray(); $idpmd = $idpmdcfg->toArray();
if (array_key_exists('name', $idpmd)) { if (array_key_exists('name', $idpmd)) {
$template->data['idp_name'] = $translator->getPreferredTranslation($idpmd['name']); $template->data['idp_name'] = $idpmd['name'];
} elseif (array_key_exists('OrganizationDisplayName', $idpmd)) { } elseif (array_key_exists('OrganizationDisplayName', $idpmd)) {
$template->data['idp_name'] = $translator->getPreferredTranslation($idpmd['OrganizationDisplayName']); $template->data['idp_name'] = $idpmd['OrganizationDisplayName'];
} else {
$template->data['idp_name'] = $idpmd['entityid'];
} }
$template->data['idp_entityid'] = $idpmd['entityid'];
// get the name of the SP // get the name of the SP
$spmd = $state['SPMetadata']; $spmd = $state['SPMetadata'];
if (array_key_exists('name', $spmd)) { if (array_key_exists('name', $spmd)) {
$template->data['sp_name'] = $translator->getPreferredTranslation($spmd['name']); $template->data['sp_name'] = $spmd['name'];
} elseif (array_key_exists('OrganizationDisplayName', $spmd)) { } elseif (array_key_exists('OrganizationDisplayName', $spmd)) {
$template->data['sp_name'] = $translator->getPreferredTranslation($spmd['OrganizationDisplayName']); $template->data['sp_name'] = $spmd['OrganizationDisplayName'];
} else {
$template->data['sp_name'] = $spmd['entityid'];
} }
$template->data['sp_entityid'] = $spmd['entityid'];
$template->send(); $template->send();
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