feat: Add various translations
This commit is contained in:
16
src/sus.js
16
src/sus.js
@@ -1,3 +1,5 @@
|
||||
import i18next from "i18next";
|
||||
|
||||
const scaleQuestions = [
|
||||
"sus-question-easy-to-use", // I thought CageCalc is easy to use
|
||||
"sus-question-like-to-use-frequently", // I would like to use CageCalc frequently
|
||||
@@ -29,11 +31,8 @@ function prepareQuestionnaire() {
|
||||
<p class="control">
|
||||
<input class="sus-slider" type="range" min="1" max="5" step="1" name=${key} required>
|
||||
<div class="slider-labels">
|
||||
<span data-i18n="strongly-disagree">Strongly Disagree</span>
|
||||
<span data-i18n="disagree">Disagree</span>
|
||||
<span data-i18n="neutral">Neutral</span>
|
||||
<span data-i18n="agree">Agree</span>
|
||||
<span data-i18n="strongly-agree">Strongly Agree</span>
|
||||
<span data-i18n="strongly-disagree">${i18next.t('strongly-disagree')}</span>
|
||||
<span data-i18n="strongly-agree">${i18next.t('strongly-agree')}</span>
|
||||
</div>
|
||||
</p>
|
||||
`;
|
||||
@@ -64,7 +63,6 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
const jsonData = {};
|
||||
|
||||
for (let [key, value] of formData.entries()) {
|
||||
console.log(key, value);
|
||||
if (key.startsWith("sws-question")) {
|
||||
jsonData[key] = parseInt(value, 10);
|
||||
} else {
|
||||
@@ -87,11 +85,11 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
if (response.ok) {
|
||||
messageDiv.className = "notification is-success";
|
||||
messageDiv.setAttribute("data-i18n", "submit-success");
|
||||
messageDiv.textContent = "Survey submitted successfully!";
|
||||
messageDiv.textContent = i18next.t("Survey submitted successfully!");
|
||||
} else {
|
||||
messageDiv.className = "notification is-danger";
|
||||
messageDiv.setAttribute("data-i18n", "submit-error");
|
||||
messageDiv.textContent = "There was an error submitting the survey.";
|
||||
messageDiv.textContent = i18next.t("There was an error submitting the survey.");
|
||||
}
|
||||
|
||||
messageDiv.classList.remove("is-hidden");
|
||||
@@ -100,7 +98,7 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
const messageDiv = document.getElementById("response-message");
|
||||
messageDiv.className = "notification is-danger";
|
||||
messageDiv.removeAttribute("data-i18n"); // For dynamic error message
|
||||
messageDiv.textContent = "Network error: " + error.message;
|
||||
messageDiv.textContent = i18next.t("Network error: {{errorMessage}}",{"errorMessage": error.message});
|
||||
messageDiv.classList.remove("is-hidden");
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user