Skip to content

Commit

Permalink
Translate error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Jul 15, 2024
1 parent aebc32e commit 82fde38
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions internal/webserver/embedded/js/xh-error-check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
document.body.addEventListener('htmx:afterRequest', function (evt) {
const errorTarget = document.getElementById("box-error")
const unexpectedServerError = errorTarget.getAttribute("data-unexpected-server-error")
const unexpectedError = errorTarget.getAttribute("data-unexpected-error")
if (evt.detail.successful) {
// Successful request, clear out alert
errorTarget.setAttribute("hidden", "true")
Expand All @@ -12,12 +14,12 @@ document.body.addEventListener('htmx:afterRequest', function (evt) {
}

console.warn("Server error", evt.detail)
errorTarget.innerText = `Unexpected server error: ${xhr.status} - ${xhr.statusText}`;
errorTarget.removeAttribute("hidden");
errorTarget.innerText = unexpectedServerError + `${xhr.status} - ${xhr.statusText}`
errorTarget.removeAttribute("hidden")
} else {
// Unspecified failure, usually caused by network error
console.error("Unexpected htmx error", evt.detail)
errorTarget.innerText = "Unexpected error, check your connection and try to refresh the page.";
errorTarget.removeAttribute("hidden");
errorTarget.innerText = unexpectedError
errorTarget.removeAttribute("hidden")
}
});
});
3 changes: 3 additions & 0 deletions internal/webserver/embedded/translations/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@
"Go left": "Ir a la izquierda"
"Go right": "Ir a la derecha"
"Session expired, please log in again.": "Sesión expirada, por favor identifícate de nuevo."
"Unexpected error, check your connection and try to refresh the page.": "Error inesperado, comprueba tu conexión y recarga la página."
"Unexpected server error": "Error inesperado en el servidor"

2 changes: 2 additions & 0 deletions internal/webserver/embedded/translations/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@
"Go left": "Aller à gauche"
"Go right": "Aller à droite"
"Session expired, please log in again.": "Session expirée, veuillez vous reconnecter."
"Unexpected error, check your connection and try to refresh the page.": "Erreur inattendue, vérifiez votre connexion et essayez d'actualiser la page."
"Unexpected server error": "Erreur de serveur inattendue"
2 changes: 1 addition & 1 deletion internal/webserver/embedded/views/partials/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{end}}

<div class="row text-start">
<div class="alert alert-danger" role="alert" hidden id="box-error">
<div class="alert alert-danger" role="alert" hidden id="box-error" data-unexpected-error='{{t .Lang "Unexpected error, check your connection and try to refresh the page."}}' data-unexpected-server-error='{{t .Lang "Unexpected server error"}}'>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions internal/webserver/embedded/views/users/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
<div class='tab-pane fade p-3 {{if eq .ActiveTab "password"}}show active{{end}}' id="password-tab-pane" role="tabpanel" aria-labelledby="password-tab"
tabindex="0">
<form hx-put="/{{.Lang}}/users/{{.User.Username}}" hx-target="body">
<form hx-put="/{{.Lang}}/users/{{.User.Username}}" hx-target="main" hx-target-400="main">
{{if eq .Session.Uuid .User.Uuid}}
<div class="mb-3">
<label for="old-password" class="form-label">{{t .Lang "Current password"}}</label>
Expand Down Expand Up @@ -103,4 +103,4 @@
</div>
</div>

<script type="text/javascript" src="/js/xh-error-check.js"></script>
<script type="text/javascript" src="/js/xh-error-check.js"></script>

0 comments on commit 82fde38

Please sign in to comment.