mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-04-29 16:59:31 -05:00
d9c6192884
Add complete internationalization (i18n) infrastructure supporting 9 languages including full Right-to-Left (RTL) support for Arabic and Hebrew. Languages supported: - English, German, French, Spanish, Dutch, Italian, Finnish (LTR) - Arabic, Hebrew (RTL with complete layout support) Core features: * Flask-Babel configuration with locale selector * Translation files for all 9 languages (480+ strings each) * Language selector UI component in header with globe icon * User language preference storage in database * RTL CSS support with automatic layout reversal * Session and user-based language persistence Model field translation system: * Created comprehensive i18n helper utilities (app/utils/i18n_helpers.py) * 17 new Jinja2 template filters for automatic translation * Support for task statuses, priorities, project statuses, invoice statuses, payment methods, expense categories, and all model enum fields * Status badge CSS classes for consistent styling Technical implementation: * Language switching via API endpoint (POST /api/language) * Direct language switching route (GET /set-language/<lang>) * RTL detection and automatic dir="rtl" attribute * Context processors for language information in all templates * Template filters registered globally Testing and quality: * 50+ unit tests covering all i18n functionality * Tests for locale selection, language switching, RTL detection * Comprehensive test coverage for all translation features Files added: - translations/es/LC_MESSAGES/messages.po (Spanish) - translations/ar/LC_MESSAGES/messages.po (Arabic) - translations/he/LC_MESSAGES/messages.po (Hebrew) - app/utils/i18n_helpers.py (translation helper functions) - app/static/css/rtl-support.css (RTL layout support) - tests/test_i18n.py (comprehensive test suite) - scripts/audit_i18n.py (translation audit tool) Files modified: - app/config.py: Added 3 languages + RTL configuration - app/routes/user.py: Language switching endpoints - app/templates/base.html: Language selector + RTL support - app/utils/context_processors.py: Language context injection - app/__init__.py: Registered i18n template filters - scripts/extract_translations.py: Updated language list - translations/*/messages.po: Added 70+ model field translations The infrastructure is production-ready. Model enum fields now automatically translate in templates using the new filters. Flash messages and some template strings remain in English until wrapped with translation markers (tracked separately for incremental implementation).
65 lines
2.6 KiB
JavaScript
65 lines
2.6 KiB
JavaScript
// Idle detection: when user is inactive, offer to stop timer at last active time
|
|
(function(){
|
|
if (window.__ttIdleLoaded) return; window.__ttIdleLoaded = true;
|
|
const IDLE_THRESHOLD_MS = 5 * 60 * 1000; // 5 minutes
|
|
const CHECK_INTERVAL_MS = 60 * 1000; // 1 minute
|
|
|
|
let lastActivity = Date.now();
|
|
let promptShown = false;
|
|
|
|
function markActive(){
|
|
lastActivity = Date.now();
|
|
promptShown = false;
|
|
}
|
|
|
|
['mousemove','keydown','scroll','click','touchstart','visibilitychange'].forEach(evt =>
|
|
document.addEventListener(evt, markActive, { passive: true })
|
|
);
|
|
|
|
async function getTimer(){
|
|
try {
|
|
const r = await fetch('/api/timer/status');
|
|
if (!r.ok) return null; const j = await r.json();
|
|
return j && j.active ? j.timer : null;
|
|
} catch(e){ return null; }
|
|
}
|
|
|
|
function formatTime(d){
|
|
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
}
|
|
|
|
async function stopAt(ts){
|
|
try {
|
|
const r = await fetch('/api/timer/stop_at', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stop_time: new Date(ts).toISOString() }) });
|
|
if (r.ok){ showToast(window.i18n?.messages?.timerStoppedInactivity || 'Timer stopped due to inactivity', 'warning'); location.reload(); }
|
|
} catch(e) {}
|
|
}
|
|
|
|
function showIdlePrompt(stopTs){
|
|
if (promptShown) return; promptShown = true;
|
|
// Create a lightweight inline prompt toast
|
|
const t = document.createElement('div');
|
|
t.className = 'toast align-items-center text-white bg-warning border-0 fade show';
|
|
t.innerHTML = `<div class="d-flex"><div class="toast-body">You seem inactive since ${formatTime(new Date(stopTs))}. Stop the timer at that time?</div><div class="d-flex gap-2 align-items-center me-2"><button class="btn btn-sm btn-light" data-act="stop">Stop</button><button class="btn btn-sm btn-outline-light" data-act="dismiss">Dismiss</button></div></div>`;
|
|
const container = document.getElementById('toast-container') || document.body;
|
|
container.appendChild(t);
|
|
t.querySelector('[data-act="stop"]').addEventListener('click', () => { t.remove(); stopAt(stopTs); });
|
|
t.querySelector('[data-act="dismiss"]').addEventListener('click', () => { t.remove(); });
|
|
setTimeout(() => { try { t.remove(); } catch(e){} }, 60_000);
|
|
}
|
|
|
|
async function tick(){
|
|
const active = await getTimer();
|
|
if (!active) return;
|
|
const idleFor = Date.now() - lastActivity;
|
|
if (idleFor >= IDLE_THRESHOLD_MS){
|
|
const stopTs = Date.now() - idleFor; // last active time
|
|
showIdlePrompt(stopTs);
|
|
}
|
|
}
|
|
|
|
setInterval(tick, CHECK_INTERVAL_MS);
|
|
})();
|
|
|
|
|