diff --git a/client/addfriends.script.js b/client/addfriends.script.js
index a8c8386..607096b 100644
--- a/client/addfriends.script.js
+++ b/client/addfriends.script.js
@@ -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', 'correo@example.com');
+ 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;
}
diff --git a/client/languageswitcher.script.js b/client/languageswitcher.script.js
new file mode 100644
index 0000000..626082f
--- /dev/null
+++ b/client/languageswitcher.script.js
@@ -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;
+}
diff --git a/client/sendassignments.script.js b/client/sendassignments.script.js
index 2317ff0..ddcb1a5 100644
--- a/client/sendassignments.script.js
+++ b/client/sendassignments.script.js
@@ -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
});
}
diff --git a/client/translation.l18n.js b/client/translation.l18n.js
new file mode 100644
index 0000000..366df88
--- /dev/null
+++ b/client/translation.l18n.js
@@ -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: 'name@example.com',
+ },
+ 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: 'correo@ejemplo.com',
+ },
+};
diff --git a/index.html b/index.html
index bb64e8c..c0a5b6e 100644
--- a/index.html
+++ b/index.html
@@ -17,16 +17,23 @@
+
+
Sorteo del Amigo Invisible
+ Switch to English
+ 🎅 Sorteo del Amigo Invisible 🎅
Sorteo del Amigo Invisible
Hola ${receiverName},
🎄Te toco ser el amigo invisible de: ${secretSantaFor}!
Recorda que es un secreto y divertite buscando un 🎁regalo🎁!!
-🌟Happy Holidays!🌟
+🌟¡Felices Fiestas!🌟
`; } -module.exports = createSecretSantaEmail; +module.exports = createSecretSantaEmailES;