Pirate Language Translator
Translate text to or from Pirate, with different flavors!
Your translation will appear here!
Shiver me timbers! Enter some text!
'; downloadBtn.style.display = 'none'; return; } // Clear previous results and hide PDF button immediately on click resultsDiv.innerHTML = 'Translating...
'; downloadBtn.style.display = 'none'; const translatedContent = translateContent(inputText, direction, flavor, keyword); resultsDiv.innerHTML = `Original: ${inputText}
Pirate Translation: ${translatedContent}
`; downloadBtn.style.display = 'block'; // Show download button }); document.getElementById('clearBtn').addEventListener('click', () => { document.getElementById('inputText').value = ''; document.querySelector('input[value="standard-to-pirate"]').checked = true; // Reset direction document.getElementById('pirateFlavor').value = 'classic'; // Reset flavor document.getElementById('pirateKeyword').value = ''; // Clear keyword document.getElementById('translationResults').innerHTML = 'Your translation will appear here!
'; document.getElementById('downloadPdfBtn').style.display = 'none'; // Hide PDF button }); // Download PDF Button document.getElementById('downloadPdfBtn').addEventListener('click', () => { const resultsDiv = document.getElementById('translationResults'); // Check if results are placeholder before attempting to get text if (resultsDiv.textContent.includes('Your translation will appear here!') || resultsDiv.textContent.includes('Translating...')) { alert("No translation to download."); return; } const originalText = resultsDiv.querySelector('p:nth-child(1) .result-text')?.textContent.trim() || ''; const pirateTranslationText = resultsDiv.querySelector('p:nth-child(2) .result-text')?.textContent.trim() || ''; if (!originalText) { // Should not happen if check passed, but for safety alert("No translation to download."); return; } // --- PDF Generation --- const doc = new jsPDF(); const margin = 15; let y = margin; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const maxLineWidth = pageWidth - 2 * margin; // Max width for text line doc.setFontSize(18); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 doc.text("Pirate Translation", margin, y); y += 15; // Space after title doc.setFontSize(12); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 // Add Original Text doc.setFontSize(14); doc.text("Original:", margin, y); y += 8; doc.setFontSize(12); const originalLines = doc.splitTextToSize(originalText, maxLineWidth); doc.text(originalLines, margin, y); y += (originalLines.length * 7) + 10; // Estimate space // Add Pirate Translation doc.setFontSize(14); doc.text("Pirate Translation:", margin, y); y += 8; doc.setFontSize(12); const pirateLines = doc.splitTextToSize(pirateTranslationText, maxLineWidth); // Check if translation fits and add pages if necessary pirateLines.forEach(line => { if (y + 7 > pageHeight - margin) { // Estimate line height + padding doc.addPage(); y = margin; doc.setFontSize(18); doc.setTextColor(52, 58, 64); doc.text("Pirate Translation (cont.)", margin, y); y += 15; doc.setFontSize(14); doc.text("Pirate Translation (cont.):", margin, y); y += 8; doc.setFontSize(12); } doc.text(line, margin, y); y += 7; // Estimate line height }); doc.save('pirate_translation.pdf'); });Key Features:
Customizable Input: Users can input any text to translate it into pirate language.
AI-Generated Translation: The tool creates a fun and engaging pirate translation based on user input.
Centered Design: The tool is perfectly centered on the page, ensuring a clean and professional look.
PDF Download: Users can download the generated pirate translation as a PDF, complete with the same color scheme for consistency.
Responsive Design: The tool is fully responsive and works seamlessly on all devices.
Benefits for End Users:
Creative Fun: Users can translate any text into pirate language for entertainment or personal projects.
Customizable Outputs: The tool allows users to tailor the generated translations based on specific text.
Educational Tool: Great for students and educators to explore language and creativity.
Portable Results: The PDF download feature allows users to save and share their translations easily.
User-Friendly Interface: The simple and intuitive design ensures that users of all ages and technical skill levels can use the tool effortlessly
