← Back to Umabot Tools


Google Translation quick setup

This app showcases how to build a custom language picker interface while leveraging Google's translation service behind the scenes.

Features

Custom Language Selector

Privacy-First Design

How It Works

Architecture Approach

The app follows a zero-backend, client-side only philosophy aligned with the umabotools project standards:

  1. Pure HTML/CSS/JavaScript: No frameworks, no build tools, no server required.
  2. Google Translate API: Uses the free Google Translate Element API for translations.
  3. Hidden Widget Pattern: Hides Google's default UI (#google_translate_element) and controls it programmatically.
  4. Event-Driven: Uses addEventListener pattern (no inline event handlers) for CSP compliance.

Technical Implementation

1. Google Translate Initialization

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
        pageLanguage: 'en',
        includedLanguages: 'en,fr,es,de',
        autoDisplay: false
    }, 'google_translate_element');
}

2. Custom Language Switching

function changeLanguage(langCode) {
    // Update button visual state
    document.querySelectorAll('.lang-btn').forEach(btn => {
        btn.classList.toggle('active', btn.dataset.lang === langCode);
    });

    // Poll for Google's dropdown element
    const poll = setInterval(() => {
        const combo = document.querySelector('.goog-te-combo');
        if (combo) {
            combo.value = langCode;
            combo.dispatchEvent(new Event('change'));
            localStorage.setItem('demo_lang_pref', langCode);
            clearInterval(poll);
        }
    }, 100);
}

Why Polling? Google's translate widget loads asynchronously. The polling mechanism waits for the hidden dropdown (.goog-te-combo) to become available, then programmatically changes its value and triggers the translation.

3. Error Handling

function checkScriptLoad() {
    if (typeof google === 'undefined' || typeof google.translate === 'undefined') {
        document.getElementById('error-banner').style.display = 'block';
    }
}

Displays a user-friendly error message if:

4. Security & Standards Compliance

CSP Compliant:

No External Frameworks:

Privacy Transparent:

Usage

Local Testing

  1. Download test_translate.html
  2. Open directly in a web browser (no server needed)
  3. Click language buttons to see instant translation

Limitations

Design Philosophy

This app demonstrates key principles from the umabotools project:

Principle Implementation
Single-page app Entire app in one HTML file
No backend Runs via file:// protocol
Security-first No inline handlers, CSP compliant
Privacy-conscious Clear disclosure, minimal data storage
Vanilla JS Zero frameworks or dependencies (except Google API)
Accessible Semantic HTML, keyboard navigation support

Use Cases

Future Enhancements

Potential improvements while maintaining the zero-backend philosophy:

Technical Requirements


License

This project is licensed under the MIT License.

InnovUmabot | https://innovumabot.com

This tool was vibe-coded with AI with strict human supervision.