mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:52:45 +01:00
chages for english translation
This commit is contained in:
+73
-25
@@ -224,7 +224,7 @@ function loadWeekData(week) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePDF(type) {
|
function generatePDF(type, trans) {
|
||||||
saveWeek();
|
saveWeek();
|
||||||
const weekNumber = getWeekNumber(currentWeek);
|
const weekNumber = getWeekNumber(currentWeek);
|
||||||
const year = currentWeek.getFullYear();
|
const year = currentWeek.getFullYear();
|
||||||
@@ -235,17 +235,22 @@ function generatePDF(type) {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ val, type })
|
body: JSON.stringify({ val, type, trans })
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
alert('PDF erfolgreich generiert');
|
alert('PDF erfolgreich generiert');
|
||||||
window.open(`../../data/${val.replace('-', " ")}.pdf`, '_blank');
|
if (trans === '') {
|
||||||
|
window.open(`../../data/${val.replace('-', " ")}_DE.pdf`, '_blank');
|
||||||
|
} else {
|
||||||
|
window.open(`../../data/${val.replace('-', " ")}_EN.pdf`, '_blank');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = data.error || 'Unbekannter Fehler';
|
const errorMessage = data.error || 'Unbekannter Fehler';
|
||||||
alert(`Fehler beim Generieren der PDF:\n\n${errorMessage}\n\nBitte kontaktieren Sie Ihren zuständigen Systemadministrator.`);
|
alert(`Fehler beim Generieren der PDF:\n\n${errorMessage}\n\nBitte kontaktieren Sie Ihren zuständigen Systemadministrator.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error generating PDF:', error);
|
console.error('Error generating PDF:', error);
|
||||||
@@ -269,11 +274,18 @@ async function sendAiTranslateRequest() {
|
|||||||
|
|
||||||
// Format the data as described in the prompt
|
// Format the data as described in the prompt
|
||||||
let promptText = '';
|
let promptText = '';
|
||||||
|
// Store original dishes for reference
|
||||||
|
const originalDishes = [];
|
||||||
|
|
||||||
data.forEach(entry => {
|
data.forEach(entry => {
|
||||||
// Add meat dish
|
// Add meat dish
|
||||||
if (entry.meat_main) {
|
if (entry.meat_main) {
|
||||||
promptText += `${entry.meat_main}\n`;
|
promptText += `${entry.meat_main}\n`;
|
||||||
|
originalDishes.push({
|
||||||
|
main: entry.meat_main,
|
||||||
|
side: entry.meat_side || ''
|
||||||
|
});
|
||||||
|
|
||||||
if (entry.meat_side) {
|
if (entry.meat_side) {
|
||||||
promptText += `${entry.meat_side}\n\n`;
|
promptText += `${entry.meat_side}\n\n`;
|
||||||
} else {
|
} else {
|
||||||
@@ -284,6 +296,11 @@ async function sendAiTranslateRequest() {
|
|||||||
// Add vegetarian dish
|
// Add vegetarian dish
|
||||||
if (entry.veggi_main) {
|
if (entry.veggi_main) {
|
||||||
promptText += `${entry.veggi_main}\n`;
|
promptText += `${entry.veggi_main}\n`;
|
||||||
|
originalDishes.push({
|
||||||
|
main: entry.veggi_main,
|
||||||
|
side: entry.veggi_side || ''
|
||||||
|
});
|
||||||
|
|
||||||
if (entry.veggi_side) {
|
if (entry.veggi_side) {
|
||||||
promptText += `${entry.veggi_side}\n\n`;
|
promptText += `${entry.veggi_side}\n\n`;
|
||||||
} else {
|
} else {
|
||||||
@@ -310,9 +327,10 @@ async function sendAiTranslateRequest() {
|
|||||||
|
|
||||||
// Show the results to the user
|
// Show the results to the user
|
||||||
console.log('AI response:', aiData.result);
|
console.log('AI response:', aiData.result);
|
||||||
|
console.log('Original dishes:', originalDishes);
|
||||||
|
|
||||||
// Create a modal to display the translation
|
// Create a modal to display the translation with original dishes
|
||||||
displayTranslation(aiData.result);
|
displayTranslation(aiData.result, originalDishes);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error sending AI request:', error);
|
console.error('Error sending AI request:', error);
|
||||||
alert('Fehler bei der KI-Anfrage: ' + error.message);
|
alert('Fehler bei der KI-Anfrage: ' + error.message);
|
||||||
@@ -321,10 +339,25 @@ async function sendAiTranslateRequest() {
|
|||||||
|
|
||||||
function sendTestTranslateRequest() {
|
function sendTestTranslateRequest() {
|
||||||
const testResponse = `[{'main_course':'Turkey schnitzel with pepper sauce','side_dish':'served with spaghetti'},{'main_course':'Lentil curry with coconut milk','side_dish':'served with rice'},{'main_course':'White cabbage stew with potatoes and ground beef','side_dish':'served with a side salad and homemade bread'},{'main_course':'Sweet potato gnocchi with cheese sauce and arugula','side_dish':'served with a side salad'},{'main_course':'Ramsons bratwurst','side_dish':'accompanied by steakhouse fries'},{'main_course':'"Poached eggs" in mustard sauce','side_dish':'served with boiled potatoes and a side salad'},{'main_course':'Chicken breast fillet in herb sauce','side_dish':'with fried potatoes and a side salad'},{'main_course':'Vegetable fritter with dip','side_dish':'served with couscous'},{'main_course':'Halibut fillet in lemon herb sauce','side_dish':'served with boiled potatoes and a side salad'},{'main_course':'Vegetable rösti with dip','side_dish':'served with potato salad'}]`;
|
const testResponse = `[{'main_course':'Turkey schnitzel with pepper sauce','side_dish':'served with spaghetti'},{'main_course':'Lentil curry with coconut milk','side_dish':'served with rice'},{'main_course':'White cabbage stew with potatoes and ground beef','side_dish':'served with a side salad and homemade bread'},{'main_course':'Sweet potato gnocchi with cheese sauce and arugula','side_dish':'served with a side salad'},{'main_course':'Ramsons bratwurst','side_dish':'accompanied by steakhouse fries'},{'main_course':'"Poached eggs" in mustard sauce','side_dish':'served with boiled potatoes and a side salad'},{'main_course':'Chicken breast fillet in herb sauce','side_dish':'with fried potatoes and a side salad'},{'main_course':'Vegetable fritter with dip','side_dish':'served with couscous'},{'main_course':'Halibut fillet in lemon herb sauce','side_dish':'served with boiled potatoes and a side salad'},{'main_course':'Vegetable rösti with dip','side_dish':'served with potato salad'}]`;
|
||||||
displayTranslation(testResponse);
|
|
||||||
|
// Beispiel-deutsche Gerichte für den Test
|
||||||
|
const testOriginalDishes = [
|
||||||
|
{ main: 'Putenschnitzel mit Pfeffersauce', side: 'mit Spaghetti' },
|
||||||
|
{ main: 'Linsencurry mit Kokosmilch', side: 'mit Reis' },
|
||||||
|
{ main: 'Weißkohleintopf mit Kartoffeln und Hackfleisch', side: 'mit Salat und hausgemachtem Brot' },
|
||||||
|
{ main: 'Süßkartoffel-Gnocchi mit Käsesauce und Rucola', side: 'mit Salat' },
|
||||||
|
{ main: 'Bärlauch-Bratwurst', side: 'mit Steakhouse-Pommes' },
|
||||||
|
{ main: '"Verlorene Eier" in Senfsauce', side: 'mit Kartoffeln und Salat' },
|
||||||
|
{ main: 'Hähnchenbrust-Filet in Kräutersauce', side: 'mit Bratkartoffeln und Salat' },
|
||||||
|
{ main: 'Gemüsepuffer mit Dip', side: 'mit Couscous' },
|
||||||
|
{ main: 'Heilbuttfilet in Zitronenkräutersauce', side: 'mit Salzkartoffeln und Salat' },
|
||||||
|
{ main: 'Gemüserösti mit Dip', side: 'mit Kartoffelsalat' }
|
||||||
|
];
|
||||||
|
|
||||||
|
displayTranslation(testResponse, testOriginalDishes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayTranslation(translationText) {
|
function displayTranslation(translationText, originalDishes = []) {
|
||||||
try {
|
try {
|
||||||
console.log('Original text:', translationText);
|
console.log('Original text:', translationText);
|
||||||
|
|
||||||
@@ -384,16 +417,17 @@ function displayTranslation(translationText) {
|
|||||||
const dishContainer = document.createElement('div');
|
const dishContainer = document.createElement('div');
|
||||||
dishContainer.classList.add('dish-container');
|
dishContainer.classList.add('dish-container');
|
||||||
|
|
||||||
|
// Deutsche Bezeichnung für das aktuelle Gericht
|
||||||
|
const originalDish = originalDishes[index] || { main: '', side: '' };
|
||||||
|
|
||||||
const dishNumber = document.createElement('div');
|
// Gericht-Header mit deutschem Original
|
||||||
dishNumber.textContent = `Gericht ${index + 1}`;
|
const dishHeader = document.createElement('div');
|
||||||
dishNumber.style.fontWeight = 'bold';
|
dishHeader.style.fontWeight = 'bold';
|
||||||
dishNumber.style.marginBottom = '5px';
|
dishHeader.style.marginBottom = '10px';
|
||||||
|
dishHeader.style.borderBottom = '1px solid #ccc';
|
||||||
const mainCourseLabel = document.createElement('label');
|
dishHeader.style.paddingBottom = '5px';
|
||||||
mainCourseLabel.textContent = 'Hauptgericht:';
|
dishHeader.style.color = '#a81411';
|
||||||
mainCourseLabel.style.marginBottom = '3px';
|
dishHeader.textContent = `${originalDish.main} ${originalDish.side}`;
|
||||||
mainCourseLabel.style.fontWeight = 'bold';
|
|
||||||
|
|
||||||
const mainCourseInput = document.createElement('input');
|
const mainCourseInput = document.createElement('input');
|
||||||
mainCourseInput.type = 'text';
|
mainCourseInput.type = 'text';
|
||||||
@@ -403,11 +437,6 @@ function displayTranslation(translationText) {
|
|||||||
mainCourseInput.style.width = '100%';
|
mainCourseInput.style.width = '100%';
|
||||||
mainCourseInput.style.boxSizing = 'border-box';
|
mainCourseInput.style.boxSizing = 'border-box';
|
||||||
|
|
||||||
const sideDishLabel = document.createElement('label');
|
|
||||||
sideDishLabel.textContent = 'Beilage:';
|
|
||||||
sideDishLabel.style.marginBottom = '3px';
|
|
||||||
sideDishLabel.style.fontWeight = 'bold';
|
|
||||||
|
|
||||||
const sideDishInput = document.createElement('input');
|
const sideDishInput = document.createElement('input');
|
||||||
sideDishInput.type = 'text';
|
sideDishInput.type = 'text';
|
||||||
sideDishInput.value = item.side_dish;
|
sideDishInput.value = item.side_dish;
|
||||||
@@ -415,10 +444,8 @@ function displayTranslation(translationText) {
|
|||||||
sideDishInput.style.width = '100%';
|
sideDishInput.style.width = '100%';
|
||||||
sideDishInput.style.boxSizing = 'border-box';
|
sideDishInput.style.boxSizing = 'border-box';
|
||||||
|
|
||||||
dishContainer.appendChild(dishNumber);
|
dishContainer.appendChild(dishHeader);
|
||||||
dishContainer.appendChild(mainCourseLabel);
|
|
||||||
dishContainer.appendChild(mainCourseInput);
|
dishContainer.appendChild(mainCourseInput);
|
||||||
dishContainer.appendChild(sideDishLabel);
|
|
||||||
dishContainer.appendChild(sideDishInput);
|
dishContainer.appendChild(sideDishInput);
|
||||||
|
|
||||||
form.appendChild(dishContainer);
|
form.appendChild(dishContainer);
|
||||||
@@ -429,8 +456,22 @@ function displayTranslation(translationText) {
|
|||||||
// Add buttons
|
// Add buttons
|
||||||
const buttonContainer = document.createElement('div');
|
const buttonContainer = document.createElement('div');
|
||||||
buttonContainer.style.display = 'flex';
|
buttonContainer.style.display = 'flex';
|
||||||
buttonContainer.style.justifyContent = 'space-between';
|
buttonContainer.style.justifyContent = 'first';
|
||||||
buttonContainer.style.marginTop = '20px';
|
buttonContainer.style.marginTop = '20px';
|
||||||
|
buttonContainer.style.alignItems = 'center';
|
||||||
|
buttonContainer.style.gap = '10px';
|
||||||
|
|
||||||
|
const generateBtn = document.createElement('button');
|
||||||
|
generateBtn.textContent = 'PDF generieren';
|
||||||
|
generateBtn.style.padding = '8px 16px';
|
||||||
|
generateBtn.style.backgroundColor = '#1e88e5';
|
||||||
|
generateBtn.style.color = 'white';
|
||||||
|
generateBtn.style.border = 'none';
|
||||||
|
generateBtn.style.borderRadius = '4px';
|
||||||
|
generateBtn.style.cursor = 'pointer';
|
||||||
|
generateBtn.onclick = () => {
|
||||||
|
generatePDF('week', translations);
|
||||||
|
};
|
||||||
|
|
||||||
const closeBtn = document.createElement('button');
|
const closeBtn = document.createElement('button');
|
||||||
closeBtn.textContent = 'Schließen';
|
closeBtn.textContent = 'Schließen';
|
||||||
@@ -464,8 +505,15 @@ function displayTranslation(translationText) {
|
|||||||
.catch(err => console.error('Fehler beim Kopieren:', err));
|
.catch(err => console.error('Fehler beim Kopieren:', err));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const disclaimer = document.createElement('p');
|
||||||
|
disclaimer.textContent = 'Hinweis: KI generierter Inhalt kann Fehler enthalten. Bitte überprüfen Sie die Übersetzungen sorgfältig.';
|
||||||
|
disclaimer.style.margin = '0'
|
||||||
|
disclaimer.style.fontWeight = 'bold';
|
||||||
|
|
||||||
|
buttonContainer.appendChild(generateBtn);
|
||||||
buttonContainer.appendChild(copyBtn);
|
buttonContainer.appendChild(copyBtn);
|
||||||
buttonContainer.appendChild(closeBtn);
|
buttonContainer.appendChild(closeBtn);
|
||||||
|
buttonContainer.appendChild(disclaimer);
|
||||||
modalContent.appendChild(buttonContainer);
|
modalContent.appendChild(buttonContainer);
|
||||||
|
|
||||||
modal.appendChild(modalContent);
|
modal.appendChild(modalContent);
|
||||||
|
|||||||
@@ -252,5 +252,5 @@ button {
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
width: 40%;
|
width: 45%;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user