Skip to content
Snippets Groups Projects
Verified Commit 7c4d8faa authored by Pavel Břoušek's avatar Pavel Břoušek
Browse files

fix: allow translation of JS alerts

parent 16001418
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,24 @@
"alternate_login_options": {
"en": "Alternate login options:"
},
"alert_webauthn_insecure_context": {
"en": "Unable to proceed with Web Authn because the context is insecure!"
},
"alert_webauthn_unavailable": {
"en": "Could not load WebAuthn library. Please try again or use other token."
},
"alert_webAuthnSignRequest_error": {
"en": "Error while signing WebAuthnSignRequest:"
},
"alert_u2f_insecure_context": {
"en": "Unable to proceed with U2F because the context is insecure!"
},
"alert_u2f_unavailable": {
"en": "Could not load U2F library. Please try again or use other token."
},
"alert_U2FSignRequest_error": {
"en": "Error while signing U2FSignRequest:"
},
"tryAgain": {
"en": "Try Again"
}
......
......@@ -272,8 +272,6 @@ if (!empty($this->data['links']))
}
echo '</ul>';
}
$this->includeAtTemplateBase('includes/footer.php');
?>
<script src="<?php echo htmlspecialchars(SimpleSAML_Module::getModuleUrl('privacyidea/js/webauthn.js'), ENT_QUOTES) ?>">
......@@ -289,5 +287,21 @@ $this->includeAtTemplateBase('includes/footer.php');
&& (($this->data['webAuthnSignRequest']) == "")
) ? 'true' : 'false'; ?>">
<meta id="privacyidea-translations" name="privacyidea-translations" content="<?php
$translations = [];
$translation_keys = [
'alert_webauthn_insecure_context', 'alert_webauthn_unavailable', 'alert_webAuthnSignRequest_error',
'alert_u2f_insecure_context', 'alert_u2f_unavailable', 'alert_U2FSignRequest_error',
];
foreach ($translation_keys as $translation_key) {
$translations[$translation_key] = $this->t(sprintf('{privacyidea:privacyidea:%s}', $translation_key));
}
echo htmlspecialchars(json_encode($translations));
?>">
<script src="<?php echo htmlspecialchars(SimpleSAML_Module::getModuleUrl('privacyidea/js/loginform.js'), ENT_QUOTES) ?>">
</script>
<?php
$this->includeAtTemplateBase('includes/footer.php');
?>
......@@ -55,6 +55,10 @@ function changeMode(newMode)
document.forms["piLoginForm"].submit();
}
function t(key) {
return JSON.parse(document.getElementById("privacyidea-translations").content)[key];
}
const step = document.getElementById("privacyidea-step").content;
if (step > "1")
......@@ -142,7 +146,7 @@ function doWebAuthn()
if (!window.isSecureContext)
{
alert("Unable to proceed with Web Authn because the context is insecure!");
alert(t("alert_webauthn_insecure_context"));
console.log("Insecure context detected: Aborting Web Authn authentication!")
changeMode("otp");
return;
......@@ -150,7 +154,7 @@ function doWebAuthn()
if (!window.pi_webauthn)
{
alert("Could not load WebAuthn library. Please try again or use other token.");
alert(t("alert_webauthn_unavailable"));
changeMode("otp");
return;
}
......@@ -180,7 +184,7 @@ function doWebAuthn()
} catch (err)
{
console.log("Error while signing WebAuthnSignRequest: " + err);
alert("Error while signing WebAuthnSignRequest: " + err);
alert(t("alert_webAuthnSignRequest_error") + " " + err);
}
}
......@@ -194,7 +198,7 @@ function doU2F()
if (!window.isSecureContext)
{
alert("Unable to proceed with U2F because the context is insecure!");
alert(t("alert_u2f_insecure_context"));
console.log("Insecure context detected: Aborting U2F authentication!")
changeMode("otp");
return;
......@@ -204,7 +208,7 @@ function doU2F()
if (requestStr === null)
{
alert("Could not load U2F library. Please try again or use other token.");
alert(t("alert_u2f_unavailable"));
changeMode("otp");
return;
}
......@@ -216,7 +220,7 @@ function doU2F()
} catch (err)
{
console.log("Error while signing U2FSignRequest: " + err);
alert("Error while signing U2FSignRequest: " + err);
alert(t("alert_U2FSignRequest_error") + " " + err);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment