A beautiful, responsive language translator for websites that supports 12+ languages with a modern UI and smooth animations.
- 12 Language Support: English, Spanish, French, German, Italian, Portuguese, Russian, Japanese, Korean, Chinese, Arabic, Hindi
- Beautiful UI: Modern gradient design with smooth animations
- Smart Translation: Pre-defined translations + API fallback
- RTL Support: Automatic text direction for Arabic and other RTL languages
- Language Detection: Detects user's browser language preference
- Keyboard Shortcut: Press
Ctrl+Shift+Tto open language selector - Responsive Design: Works perfectly on mobile and desktop
- Loading States: Visual feedback during translation
- Error Handling: Graceful error handling with user notifications
- Download the files to your project directory
- Open
index.htmlin your browser - Click the globe button (π) in the top-right corner
- Select your language and watch the magic happen!
website-translator/
βββ index.html # Main website with sample content
βββ style.css # Beautiful styling and animations
βββ translator.js # Translation system and logic
βββ demo.html # Minimal demo page
βββ package.json # Project metadata
βββ README.md # This file
- Copy the files to your project:
style.cssβ Your CSS directorytranslator.jsβ Your JavaScript directory
- Add the translator button to your HTML:
<link rel="stylesheet" href="style.css"> <script src="translator.js"></script>
<!-- Add to your HTML head -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/your-username/website-translator/style.css">
<script src="https://cdn.jsdelivr.net/gh/your-username/website-translator/translator.js"></script>Add the translator button to your HTML:
<div class="translator-container">
<button id="translateBtn" class="translate-button">
<span class="translate-icon">π</span>
<span class="translate-text">Translate</span>
</button>
<div class="language-selector" id="languageSelector">
<div class="language-option" data-lang="en">English</div>
<div class="language-option" data-lang="es">EspaΓ±ol</div>
<div class="language-option" data-lang="fr">FranΓ§ais</div>
<!-- Add more languages as needed -->
</div>
</div>Add data-translate attributes to your HTML elements:
<h1 data-translate="hero.title">Welcome to Our Website</h1>
<p data-translate="hero.subtitle">Discover amazing features</p>
<button data-translate="hero.button">Get Started</button>Extend the translations object in translator.js:
// Add new language
translations: {
'de': {
'hero.title': 'Willkommen auf unserer Website',
'hero.subtitle': 'Entdecken Sie erstaunliche Funktionen',
'hero.button': 'Loslegen'
}
}Modify style.css to match your brand:
.translate-button {
background: linear-gradient(135deg, #your-color1 0%, #your-color2 100%);
/* Customize colors, fonts, sizes, etc. */
}- Add language option to HTML:
<div class="language-option" data-lang="new-lang">New Language</div>- Add translations to JavaScript:
translations: {
'new-lang': {
'key': 'translated text'
}
}Replace the default translation API in translator.js:
async translateText(text, targetLanguage) {
// Replace with your preferred API (Google Translate, Azure, etc.)
const response = await fetch('your-api-endpoint', {
method: 'POST',
headers: { 'Authorization': 'Bearer your-api-key' },
body: JSON.stringify({ text, targetLanguage })
});
return await response.json();
}| Language | Code | Status |
|---|---|---|
| English | en | β Complete |
| Spanish | es | β Complete |
| French | fr | β Complete |
| German | de | π Partial |
| Italian | it | π Partial |
| Portuguese | pt | π Partial |
| Russian | ru | π Partial |
| Japanese | ja | π Partial |
| Korean | ko | π Partial |
| Chinese | zh | π Partial |
| Arabic | ar | π Partial |
| Hindi | hi | π Partial |
Ctrl + Shift + T- Open language selector
- β Chrome 60+
- β Firefox 55+
- β Safari 12+
- β Edge 79+
- β Mobile browsers
async translateText(text, targetLanguage) {
const response = await fetch('https://translation.googleapis.com/language/translate/v2', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
q: text,
target: targetLanguage,
format: 'text'
})
});
const data = await response.json();
return data.data.translations[0].translatedText;
}async translateText(text, targetLanguage) {
const response = await fetch('https://api.cognitive.microsofttranslator.com/translate', {
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify([{
text: text,
to: targetLanguage
}])
});
const data = await response.json();
return data[0].translations[0].text;
}-
Translations not working?
- Check browser console for errors
- Ensure all files are properly linked
- Verify
data-translateattributes are correct
-
Styling issues?
- Check CSS file is loaded
- Verify no CSS conflicts with your existing styles
- Check responsive breakpoints
-
API errors?
- Verify API key is correct
- Check network connectivity
- Review API rate limits
MIT License - feel free to use in your projects!
- Fork the repository
- Create a feature branch
- Add your translations/improvements
- Submit a pull request
If you need help or have questions:
- Open an issue on GitHub
- Check the troubleshooting section
- Review the code comments
Made with β€οΈ for global accessibility