|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>Language Translator</title> |
| 7 | + <link rel="stylesheet" href="lt.css" /> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + <div class="container"> |
| 11 | + <h1>Language Translator</h1> |
| 12 | + |
| 13 | + <div class="translator-box"> |
| 14 | + <textarea id="inputText" placeholder="Enter text here..."></textarea> |
| 15 | + |
| 16 | + <div class="controls"> |
| 17 | + <select id="fromLang"> |
| 18 | + <option value="en">English</option> |
| 19 | + <option value="es">Spanish</option> |
| 20 | + <option value="fr">French</option> |
| 21 | + <option value="de">German</option> |
| 22 | + <option value="hi">Hindi</option> |
| 23 | + <option value="ta">Tamil</option> |
| 24 | + <option value="te">Telugu</option> |
| 25 | + <option value="ja">Japanese</option> |
| 26 | + <option value="zh">Chinese</option> |
| 27 | + </select> |
| 28 | + |
| 29 | + <span>➡️</span> |
| 30 | + |
| 31 | + <select id="toLang"> |
| 32 | + <option value="hi">Hindi</option> |
| 33 | + <option value="en">English</option> |
| 34 | + <option value="fr">French</option> |
| 35 | + <option value="es">Spanish</option> |
| 36 | + <option value="de">German</option> |
| 37 | + <option value="ta">Tamil</option> |
| 38 | + <option value="te">Telugu</option> |
| 39 | + <option value="ja">Japanese</option> |
| 40 | + <option value="zh">Chinese</option> |
| 41 | + </select> |
| 42 | + </div> |
| 43 | + |
| 44 | + <button id="translateBtn">Translate</button> |
| 45 | + |
| 46 | + <textarea id="outputText" placeholder="Translation will appear here..." readonly></textarea> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + |
| 50 | + <script src="Translator.js"></script> |
| 51 | +</body> |
| 52 | +</html> |
| 53 | + |
| 54 | +document.getElementById("translateBtn").addEventListener("click", () => { |
| 55 | + const inputText = document.getElementById("inputText").value.trim(); |
| 56 | + const fromLang = document.getElementById("fromLang").value; |
| 57 | + const toLang = document.getElementById("toLang").value; |
| 58 | + const outputText = document.getElementById("outputText"); |
| 59 | + |
| 60 | + if (inputText === "") { |
| 61 | + outputText.value = "Please enter some text to translate!"; |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + const url = `https://api.mymemory.translated.net/get?q=${encodeURIComponent(inputText)}&langpair=${fromLang}|${toLang}`; |
| 66 | + |
| 67 | + outputText.value = "Translating... ⏳"; |
| 68 | + |
| 69 | + fetch(url) |
| 70 | + .then(response => response.json()) |
| 71 | + .then(data => { |
| 72 | + const translated = data.responseData.translatedText; |
| 73 | + outputText.value = translated; |
| 74 | + }) |
| 75 | + .catch(() => { |
| 76 | + outputText.value = "Error: Could not translate text."; |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +body { |
| 81 | + font-family: 'Poppins', sans-serif; |
| 82 | + background: linear-gradient(to right, #8360c3, #2ebf91); |
| 83 | + display: flex; |
| 84 | + justify-content: center; |
| 85 | + align-items: center; |
| 86 | + height: 100vh; |
| 87 | + margin: 0; |
| 88 | +} |
| 89 | + |
| 90 | +.container { |
| 91 | + background: #fff; |
| 92 | + border-radius: 15px; |
| 93 | + padding: 30px; |
| 94 | + width: 400px; |
| 95 | + box-shadow: 0 4px 15px rgba(0,0,0,0.2); |
| 96 | + text-align: center; |
| 97 | +} |
| 98 | + |
| 99 | +h1 { |
| 100 | + margin-bottom: 20px; |
| 101 | + color: #333; |
| 102 | +} |
| 103 | + |
| 104 | +.translator-box { |
| 105 | + display: flex; |
| 106 | + flex-direction: column; |
| 107 | + gap: 15px; |
| 108 | +} |
| 109 | + |
| 110 | +textarea { |
| 111 | + width: 100%; |
| 112 | + height: 100px; |
| 113 | + border-radius: 10px; |
| 114 | + border: 1px solid #ccc; |
| 115 | + padding: 10px; |
| 116 | + font-size: 16px; |
| 117 | + resize: none; |
| 118 | +} |
| 119 | + |
| 120 | +.controls { |
| 121 | + display: flex; |
| 122 | + justify-content: space-between; |
| 123 | + align-items: center; |
| 124 | +} |
| 125 | + |
| 126 | +select { |
| 127 | + padding: 8px; |
| 128 | + border-radius: 8px; |
| 129 | + border: 1px solid #ccc; |
| 130 | + font-size: 14px; |
| 131 | +} |
| 132 | + |
| 133 | +button { |
| 134 | + background: #2ebf91; |
| 135 | + color: white; |
| 136 | + border: none; |
| 137 | + padding: 10px; |
| 138 | + border-radius: 8px; |
| 139 | + font-size: 16px; |
| 140 | + cursor: pointer; |
| 141 | + transition: 0.3s; |
| 142 | +} |
| 143 | + |
| 144 | +button:hover { |
| 145 | + background: #27a380; |
| 146 | +} |
0 commit comments