Refactor: Improve i18n support and fix multiplication steps layout
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- Integrate i18n translations for difficulty descriptions - Fix intermediate steps alignment in long multiplication display - Simplify spacing calculations for better layout consistency - Update translation files for all supported languages (en, es, el, sv)
This commit is contained in:
parent
382b0b235c
commit
b907866c85
7 changed files with 23 additions and 31 deletions
|
|
@ -448,8 +448,8 @@ function handleSubmitAnswer() {
|
||||||
showFeedback('🎉 Correct! +1 point', 'correct');
|
showFeedback('🎉 Correct! +1 point', 'correct');
|
||||||
updateScore();
|
updateScore();
|
||||||
|
|
||||||
// Check if reached 20 points
|
// Check if reached 10 points
|
||||||
if (gameState.points >= 20) {
|
if (gameState.points >= 10) {
|
||||||
showVictoryModal();
|
showVictoryModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -502,7 +502,7 @@ function clearFeedback() {
|
||||||
* Update score display
|
* Update score display
|
||||||
*/
|
*/
|
||||||
function updateScore() {
|
function updateScore() {
|
||||||
pointsScoreDisplay.textContent = `${gameState.points}/20`;
|
pointsScoreDisplay.textContent = `${gameState.points}/10`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -643,7 +643,7 @@ function updateUIText() {
|
||||||
modalTitle.textContent = i18n.t('congratulations');
|
modalTitle.textContent = i18n.t('congratulations');
|
||||||
}
|
}
|
||||||
if (modalText) {
|
if (modalText) {
|
||||||
modalText.textContent = i18n.t('youReached20Points');
|
modalText.textContent = i18n.t('youReached10Points');
|
||||||
}
|
}
|
||||||
if (playAgainButton) {
|
if (playAgainButton) {
|
||||||
playAgainButton.textContent = i18n.t('playAgain');
|
playAgainButton.textContent = i18n.t('playAgain');
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
<section class="score-section">
|
<section class="score-section">
|
||||||
<div class="score-box">
|
<div class="score-box">
|
||||||
<p class="score-label">Points:</p>
|
<p class="score-label">Points:</p>
|
||||||
<p class="score-value" id="points-score">0/20</p>
|
<p class="score-value" id="points-score">0/10</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
||||||
34
script.js
34
script.js
|
|
@ -66,8 +66,11 @@ window.addEventListener('load', async () => {
|
||||||
*/
|
*/
|
||||||
function handleDifficultyChange() {
|
function handleDifficultyChange() {
|
||||||
gameState.difficulty = parseInt(difficultySlider.value);
|
gameState.difficulty = parseInt(difficultySlider.value);
|
||||||
difficultyDisplay.textContent = gameState.difficulty;
|
document.getElementById('difficulty-display').textContent = gameState.difficulty;
|
||||||
difficultyDescription.textContent = difficultyConfig[gameState.difficulty].description;
|
const config = difficultyConfig[gameState.difficulty];
|
||||||
|
if (config && config.descriptionKey) {
|
||||||
|
difficultyDescription.textContent = i18n.t(config.descriptionKey);
|
||||||
|
}
|
||||||
generateNewProblem();
|
generateNewProblem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,19 +169,8 @@ function displayProblem() {
|
||||||
|
|
||||||
for (let i = 0; i < steps.length; i++) {
|
for (let i = 0; i < steps.length; i++) {
|
||||||
const stepProduct = steps[i].product.toString();
|
const stepProduct = steps[i].product.toString();
|
||||||
const totalWidth = stepProduct.length + steps[i].shift;
|
const totalWidth = maxResultWidth;
|
||||||
intermediateHTML += '<div class="line" style="justify-content: flex-start; gap: 5px;">';
|
intermediateHTML += '<div class="line" style="justify-content: flex-end; gap: 5px;">';
|
||||||
|
|
||||||
// Each row is offset one position to the left
|
|
||||||
// Add offset spaces at the beginning (left side)
|
|
||||||
for (let offset = 0; offset < i; offset++) {
|
|
||||||
intermediateHTML += '<span style="width: 90px;"></span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add empty spaces for shift
|
|
||||||
for (let s = 0; s < steps[i].shift; s++) {
|
|
||||||
intermediateHTML += '<span style="width: 90px;"></span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add input fields for each digit
|
// Add input fields for each digit
|
||||||
for (let j = 0; j < stepProduct.length; j++) {
|
for (let j = 0; j < stepProduct.length; j++) {
|
||||||
|
|
@ -186,9 +178,9 @@ function displayProblem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add trailing empty spaces on the right
|
// Add trailing empty spaces on the right
|
||||||
const trailingSpaces = maxResultWidth - totalWidth - i;
|
const trailingSpaces = i;
|
||||||
for (let e = 0; e < trailingSpaces; e++) {
|
for (let e = 0; e < trailingSpaces; e++) {
|
||||||
intermediateHTML += '<span style="width: 90px;"></span>';
|
intermediateHTML += `<span style="width: 90px"></span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediateHTML += '</div>';
|
intermediateHTML += '</div>';
|
||||||
|
|
@ -448,8 +440,8 @@ function handleSubmitAnswer() {
|
||||||
showFeedback('🎉 Correct! +1 point', 'correct');
|
showFeedback('🎉 Correct! +1 point', 'correct');
|
||||||
updateScore();
|
updateScore();
|
||||||
|
|
||||||
// Check if reached 20 points
|
// Check if reached 10 points
|
||||||
if (gameState.points >= 20) {
|
if (gameState.points >= 10) {
|
||||||
showVictoryModal();
|
showVictoryModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -502,7 +494,7 @@ function clearFeedback() {
|
||||||
* Update score display
|
* Update score display
|
||||||
*/
|
*/
|
||||||
function updateScore() {
|
function updateScore() {
|
||||||
pointsScoreDisplay.textContent = `${gameState.points}/20`;
|
pointsScoreDisplay.textContent = `${gameState.points}/10`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -643,7 +635,7 @@ function updateUIText() {
|
||||||
modalTitle.textContent = i18n.t('congratulations');
|
modalTitle.textContent = i18n.t('congratulations');
|
||||||
}
|
}
|
||||||
if (modalText) {
|
if (modalText) {
|
||||||
modalText.textContent = i18n.t('youReached20Points');
|
modalText.textContent = i18n.t('youReached10Points');
|
||||||
}
|
}
|
||||||
if (playAgainButton) {
|
if (playAgainButton) {
|
||||||
playAgainButton.textContent = i18n.t('playAgain');
|
playAgainButton.textContent = i18n.t('playAgain');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
"points": "Πόντοι:",
|
"points": "Πόντοι:",
|
||||||
"newProblem": "Νέο Πρόβλημα",
|
"newProblem": "Νέο Πρόβλημα",
|
||||||
"congratulations": "🎉 Συγχαρητήρια! 🎉",
|
"congratulations": "🎉 Συγχαρητήρια! 🎉",
|
||||||
"youReached20Points": "Έφτασες τους 20 πόντους!",
|
"youReached10Points": "Έφτασες τους 10 πόντους!",
|
||||||
"playAgain": "Παίξε Ξανά",
|
"playAgain": "Παίξε Ξανά",
|
||||||
"correct": "Σωστό! Εξαιρετική δουλειά! 🎉",
|
"correct": "Σωστό! Εξαιρετική δουλειά! 🎉",
|
||||||
"incorrect": "Λάθος. Προσπάθησε ξανά! 💪"
|
"incorrect": "Λάθος. Προσπάθησε ξανά! 💪"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
"points": "Points:",
|
"points": "Points:",
|
||||||
"newProblem": "New Problem",
|
"newProblem": "New Problem",
|
||||||
"congratulations": "🎉 Congratulations! 🎉",
|
"congratulations": "🎉 Congratulations! 🎉",
|
||||||
"youReached20Points": "You've reached 20 points!",
|
"youReached10Points": "You've reached 10 points!",
|
||||||
"playAgain": "Play Again",
|
"playAgain": "Play Again",
|
||||||
"correct": "Correct! Great job! 🎉",
|
"correct": "Correct! Great job! 🎉",
|
||||||
"incorrect": "Incorrect. Try again! 💪"
|
"incorrect": "Incorrect. Try again! 💪"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
"points": "Puntos:",
|
"points": "Puntos:",
|
||||||
"newProblem": "Nuevo Problema",
|
"newProblem": "Nuevo Problema",
|
||||||
"congratulations": "🎉 ¡Felicitaciones! 🎉",
|
"congratulations": "🎉 ¡Felicitaciones! 🎉",
|
||||||
"youReached20Points": "¡Has alcanzado 20 puntos!",
|
"youReached10Points": "¡Has alcanzado 10 puntos!",
|
||||||
"playAgain": "Jugar de Nuevo",
|
"playAgain": "Jugar de Nuevo",
|
||||||
"correct": "¡Correcto! ¡Excelente trabajo! 🎉",
|
"correct": "¡Correcto! ¡Excelente trabajo! 🎉",
|
||||||
"incorrect": "Incorrecto. ¡Intenta de nuevo! 💪"
|
"incorrect": "Incorrecto. ¡Intenta de nuevo! 💪"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
"points": "Poäng:",
|
"points": "Poäng:",
|
||||||
"newProblem": "Nytt Problem",
|
"newProblem": "Nytt Problem",
|
||||||
"congratulations": "🎉 Grattis! 🎉",
|
"congratulations": "🎉 Grattis! 🎉",
|
||||||
"youReached20Points": "Du har nått 20 poäng!",
|
"youReached10Points": "Du har nått 10 poäng!",
|
||||||
"playAgain": "Spela Igen",
|
"playAgain": "Spela Igen",
|
||||||
"correct": "Rätt! Bra jobbat! 🎉",
|
"correct": "Rätt! Bra jobbat! 🎉",
|
||||||
"incorrect": "Fel. Försök igen! 💪"
|
"incorrect": "Fel. Försök igen! 💪"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue