Language-Translator / index.html
hfexample's picture
Initial commit: multilingual-translator
5691015
Raw History Blame Contribute Delete
12.9 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Multilingual Translator</title>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
overflow-x: hidden;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: linear-gradient(to bottom right, #1a1a2e, #16213e, #0f3460);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
position: relative;
overflow-x: hidden;
}
body::before {
content: '';
position: absolute;
width: 500px;
height: 500px;
background: radial-gradient(circle, rgba(94, 53, 177, 0.3), transparent);
top: -100px;
right: -100px;
border-radius: 50%;
animation: pulse 8s ease-in-out infinite;
}
body::after {
content: '';
position: absolute;
width: 400px;
height: 400px;
background: radial-gradient(circle, rgba(0, 180, 219, 0.3), transparent);
bottom: -100px;
left: -100px;
border-radius: 50%;
animation: pulse 6s ease-in-out infinite reverse;
}
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 0.5; }
50% { transform: scale(1.2); opacity: 0.8; }
}
.container {
max-width: 1100px;
width: 100%;
position: relative;
z-index: 1;
}
.translator-card {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 24px;
padding: 50px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
h1 {
color: #fff;
font-size: 3rem;
font-weight: 700;
text-align: center;
margin-bottom: 12px;
letter-spacing: -1px;
background: linear-gradient(135deg, #fff 0%, #a8c0ff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
text-align: center;
color: rgba(255, 255, 255, 0.7);
margin-bottom: 50px;
font-size: 1.1rem;
font-weight: 400;
}
.controls {
display: flex;
gap: 20px;
margin-bottom: 35px;
align-items: flex-end;
justify-content: center;
}
.select-group {
flex: 0 0 auto;
min-width: 280px;
}
label {
display: block;
color: rgba(255, 255, 255, 0.9);
font-size: 0.95rem;
margin-bottom: 10px;
font-weight: 600;
letter-spacing: 0.5px;
text-transform: uppercase;
}
select {
width: 100%;
padding: 14px 18px;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 12px;
color: #fff;
font-size: 1rem;
font-family: 'Space Grotesk', sans-serif;
cursor: pointer;
transition: all 0.3s ease;
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23fff' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 12px center;
background-size: 14px;
}
select option {
background: #1a1a2e;
color: #fff;
padding: 12px;
}
select:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.3);
}
select:focus {
outline: none;
border-color: #5e35b1;
box-shadow: 0 0 0 3px rgba(94, 53, 177, 0.2);
}
button {
padding: 16px 50px;
background: linear-gradient(135deg, #5e35b1, #00b4db);
border: none;
border-radius: 14px;
color: #fff;
font-size: 1.05rem;
font-weight: 700;
cursor: pointer;
transition: all 0.3s ease;
font-family: 'Space Grotesk', sans-serif;
box-shadow: 0 8px 24px rgba(94, 53, 177, 0.5);
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
overflow: hidden;
}
button::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: left 0.5s;
}
button:hover::before {
left: 100%;
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 12px 32px rgba(94, 53, 177, 0.7);
}
button:active {
transform: translateY(-1px);
}
.translation-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 25px;
margin-bottom: 30px;
}
.text-box {
display: flex;
flex-direction: column;
min-width: 0;
position: relative;
}
.box-label {
color: #fff;
font-size: 1rem;
margin-bottom: 12px;
font-weight: 700;
display: flex;
align-items: center;
gap: 10px;
text-transform: uppercase;
letter-spacing: 1px;
}
.box-label::before {
content: '';
width: 5px;
height: 24px;
background: linear-gradient(to bottom, #5e35b1, #00b4db);
border-radius: 3px;
box-shadow: 0 0 10px rgba(94, 53, 177, 0.5);
}
textarea {
width: 100%;
height: 240px;
min-height: 240px;
max-height: 400px;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border: 2px solid rgba(255, 255, 255, 0.2);
border-radius: 16px;
color: #fff;
font-size: 1.05rem;
font-family: 'Space Grotesk', sans-serif;
resize: vertical;
transition: all 0.3s ease;
line-height: 1.7;
overflow-y: auto;
overflow-x: hidden;
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}
textarea:focus {
outline: none;
border-color: #5e35b1;
background: rgba(255, 255, 255, 0.15);
box-shadow: 0 0 0 4px rgba(94, 53, 177, 0.3), inset 0 2px 8px rgba(0, 0, 0, 0.2);
}
textarea::placeholder {
color: rgba(255, 255, 255, 0.5);
font-style: italic;
}
.output-box {
width: 100%;
height: 240px;
min-height: 240px;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border: 2px solid rgba(255, 255, 255, 0.2);
border-radius: 16px;
color: rgba(255, 255, 255, 0.7);
font-size: 1.05rem;
font-family: 'Space Grotesk', sans-serif;
line-height: 1.7;
white-space: pre-wrap;
word-wrap: break-word;
overflow-y: auto;
overflow-x: hidden;
font-style: italic;
box-sizing: border-box;
box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
}
.output-box:hover {
border-color: rgba(255, 255, 255, 0.3);
}
/* Custom scrollbar for webkit browsers */
.output-box::-webkit-scrollbar,
textarea::-webkit-scrollbar {
width: 8px;
}
.output-box::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
}
.output-box::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
background: rgba(94, 53, 177, 0.5);
border-radius: 10px;
}
.output-box::-webkit-scrollbar-thumb:hover,
textarea::-webkit-scrollbar-thumb:hover {
background: rgba(94, 53, 177, 0.7);
}
.output-box.loading {
display: flex;
align-items: center;
justify-content: center;
color: rgba(255, 255, 255, 0.6);
font-style: normal;
}
.output-box.has-translation {
color: #fff;
font-style: normal;
border-color: rgba(94, 53, 177, 0.4);
background: rgba(255, 255, 255, 0.12);
}
.loader {
border: 4px solid rgba(255, 255, 255, 0.15);
border-top: 4px solid #5e35b1;
border-radius: 50%;
width: 36px;
height: 36px;
animation: spin 1s linear infinite;
margin-right: 12px;
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.footer {
text-align: center;
color: rgba(255, 255, 255, 0.5);
font-size: 0.9rem;
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-weight: 500;
}
@media (max-width: 768px) {
body {
padding: 15px;
align-items: flex-start;
padding-top: 30px;
}
.container {
max-width: 100%;
}
.translator-card {
padding: 30px 20px;
}
h1 {
font-size: 2rem;
margin-bottom: 8px;
}
.subtitle {
font-size: 0.95rem;
margin-bottom: 30px;
}
.translation-grid {
grid-template-columns: 1fr;
gap: 25px;
}
.controls {
flex-direction: column;
gap: 15px;
align-items: stretch;
}
.select-group {
min-width: 100%;
}
button {
width: 100%;
padding: 16px 20px;
}
textarea,
.output-box {
height: 200px;
min-height: 200px;
font-size: 1rem;
padding: 16px;
}
.box-label {
font-size: 0.9rem;
}
}
@media (max-width: 480px) {
.translator-card {
padding: 20px 15px;
border-radius: 20px;
}
h1 {
font-size: 1.7rem;
}
.subtitle {
font-size: 0.9rem;
}
textarea,
.output-box {
height: 180px;
min-height: 180px;
padding: 14px;
font-size: 0.95rem;
}
.box-label {
font-size: 0.85rem;
}
button {
padding: 14px 20px;
font-size: 0.95rem;
}
}
</style>
</head>
<body>
<div class="container">
<div class="translator-card">
<h1>Language Translator</h1>
<p class="subtitle">Translate text between 19+ languages instantly</p>
<div class="controls">
<div class="select-group">
<label for="language">Target Language</label>
<select id="language">
{% for code, name in languages %}
<option value="{{ code }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<button id="translateBtn">Translate Now</button>
</div>
<div class="translation-grid">
<div class="text-box">
<div class="box-label">Original Text</div>
<textarea id="text" placeholder="Enter text to translate..."></textarea>
</div>
<div class="text-box">
<div class="box-label">Translation</div>
<div id="translated" class="output-box">Translation will appear here...</div>
</div>
</div>
<div class="footer">
Powered by Deep Translator API
</div>
</div>
</div>
<script>
const translateBtn = document.getElementById('translateBtn');
const textInput = document.getElementById('text');
const langSelect = document.getElementById('language');
const outputBox = document.getElementById('translated');
translateBtn.addEventListener('click', async () => {
const text = textInput.value.trim();
const lang = langSelect.value;
if (!text) {
outputBox.textContent = 'Please enter some text to translate.';
return;
}
// Show loading state
outputBox.className = 'output-box loading';
outputBox.innerHTML = '<div class="loader"></div>Translating...';
try {
const formData = new URLSearchParams();
formData.append('text', text);
formData.append('language', lang);
const response = await fetch('/translate', {
method: 'POST',
body: formData
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Translation failed');
}
const data = await response.json();
outputBox.className = 'output-box has-translation';
outputBox.textContent = data.translated;
outputBox.scrollTop = 0;
} catch (error) {
outputBox.className = 'output-box has-translation';
outputBox.textContent = '❌ Error: ' + error.message;
}
});
// Ctrl+Enter to translate
textInput.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 'Enter') {
translateBtn.click();
}
});
</script>
</body>
</html>