-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from MauGaP/feature/localization
regionalization
- Loading branch information
Showing
10 changed files
with
160 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,14 @@ function addFriendRow() { | |
idInput.value = table.rows.length; // Sequential ID based on the row count | ||
idCell.appendChild(idInput); | ||
|
||
// Create name cell | ||
// Name cell with translated default value | ||
var nameCell = newRow.insertCell(1); | ||
var nameInput = createInputField('text', 'name', 'Nombre'); | ||
var nameInput = createInputField('text', 'name', languageData[currentLanguage].defaultName); | ||
nameCell.appendChild(nameInput); | ||
|
||
// Create email cell | ||
// Email cell with translated default value | ||
var emailCell = newRow.insertCell(2); | ||
var emailInput = createInputField('email', 'email', '[email protected]'); | ||
var emailInput = createInputField('email', 'email', languageData[currentLanguage].defaultEmail); | ||
emailCell.appendChild(emailInput); | ||
|
||
// Create exclude cell | ||
|
@@ -26,11 +26,11 @@ function addFriendRow() { | |
excludeCell.appendChild(excludeInput); | ||
} | ||
|
||
function createInputField(type, name, value) { | ||
function createInputField(type, name, defaultValue) { | ||
var input = document.createElement('input'); | ||
input.type = type; | ||
input.name = name; | ||
input.value = value; | ||
input.onblur = saveToSessionStorage; // Attach the onblur event | ||
input.value = defaultValue; | ||
input.onblur = saveToSessionStorage; | ||
return input; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function switchLanguage(lang) { | ||
document.getElementById('headerTitle').textContent = languageData[lang]['headerTitle']; | ||
document.getElementById('addFriendsButton').textContent = languageData[lang]['addFriends']; | ||
document.getElementById('clearAllButton').textContent = languageData[lang]['clearAll']; | ||
document.getElementById('sendEmailsButton').textContent = languageData[lang]['sendEmails']; | ||
document.getElementById('nameTh').textContent = languageData[lang]['nameTh']; | ||
document.getElementById('emailTh').textContent = languageData[lang]['emailTh']; | ||
document.getElementById('exclusionTh').textContent = languageData[lang]['exclusionTh']; | ||
|
||
document.querySelectorAll("#friendsTable input[name='name']").forEach(input => { | ||
if (input.value === languageData['en'].defaultName || input.value === languageData['es'].defaultName) { | ||
input.value = languageData[lang].defaultName; | ||
} | ||
}); | ||
document.querySelectorAll("#friendsTable input[name='email']").forEach(input => { | ||
if (input.value === languageData['en'].defaultEmail || input.value === languageData['es'].defaultEmail) { | ||
input.value = languageData[lang].defaultEmail; | ||
} | ||
}); | ||
} | ||
|
||
function toggleLanguage() { | ||
currentLanguage = currentLanguage === 'es' ? 'en' : 'es'; | ||
sessionStorage.setItem('preferredLanguage', currentLanguage); // Store in session storage | ||
switchLanguage(currentLanguage); | ||
updateLanguageSwitcherText(); | ||
} | ||
|
||
function updateLanguageSwitcherText() { | ||
const switcherText = currentLanguage === 'es' ? 'Switch to English' : 'Cambiar a Español'; | ||
document.getElementById('languageSwitcher').textContent = switcherText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
function sendAssignmentsToServer() { | ||
const assignments = JSON.parse(sessionStorage.getItem('secretSantaAssignments')); | ||
if (!assignments) { | ||
console.error('No assignments found in session storage'); | ||
return; | ||
} | ||
const assignments = JSON.parse(sessionStorage.getItem('secretSantaAssignments')); | ||
const language = sessionStorage.getItem('preferredLanguage') || 'es'; // Default to Spanish if not set | ||
|
||
fetch('http://localhost:3500/send-emails', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ assignments: assignments }) | ||
}) | ||
if (!assignments) { | ||
console.error('No assignments found in session storage'); | ||
return; | ||
} | ||
|
||
fetch('http://localhost:3500/send-emails', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
assignments: assignments, | ||
language: language, // Include the language preference in the request | ||
}), | ||
}) | ||
.then(response => response.text()) | ||
.then(data => { | ||
console.log('Response from server:', data); | ||
// You can add more UI feedback here, e.g., a success message | ||
console.log('Response from server:', data); | ||
// Additional UI feedback for success can be added here | ||
}) | ||
.catch(error => { | ||
console.error('Error sending assignments:', error); | ||
// Handle the error in the UI as well | ||
console.error('Error sending assignments:', error); | ||
// Handle the error in the UI as well | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const languageData = { | ||
en: { | ||
headerTitle: `🎅 Secret Santa's Draw 🎅`, | ||
addFriends: 'Add More Friends', | ||
clearAll: 'Clear All', | ||
sendEmails: 'Send Emails', | ||
nameTh: 'Name', | ||
emailTh: 'Email', | ||
exclusionTh: 'Exclusions (Comma separated names)', | ||
defaultName: 'Name', | ||
defaultEmail: '[email protected]', | ||
}, | ||
es: { | ||
headerTitle: '🎅 Sorteo del Amigo Invisible 🎅', | ||
addFriends: 'Añadir más amigos', | ||
clearAll: 'Borrar todos', | ||
sendEmails: 'Enviar correos', | ||
nameTh: 'Nombre', | ||
emailTh: 'Correo', | ||
exclusionTh: 'Exclusiones (Nombres separados por coma)', | ||
defaultName: 'Nombre', | ||
defaultEmail: '[email protected]', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function createSecretSantaEmailEN(receiverName, secretSantaFor) { | ||
return ` | ||
<html> | ||
<head> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
color: #333; | ||
text-align: center; | ||
padding: 20px; | ||
} | ||
.container { | ||
background-color: #fff; | ||
border-radius: 10px; | ||
padding: 20px; | ||
margin: 20px auto; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
.header { | ||
font-size: 24px; | ||
color: #d33; | ||
} | ||
.message { | ||
font-size: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header">🎅 Secret Santa Assignment 🎅</div> | ||
<div class="message"> | ||
<p>Hello <strong>${receiverName}</strong>,</p> | ||
<p>🎄 You have been chosen to be the Secret Santa for: <strong>${secretSantaFor}</strong>!</p> | ||
<p>Remember, it's a secret and have fun picking a 🎁gift🎁!!</p> | ||
<p>🌟Happy Holidays!🌟</p> | ||
</div> | ||
</div> | ||
</body> | ||
</html>`; | ||
} | ||
|
||
module.exports = createSecretSantaEmailEN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters