Implement lightweight offline i18n system with French/English support

**Core System:**
- Add i18n.js translation library with data-attribute support
- Create translation files (fr.json, en.json) with offline support
- Store language preference in SQLite config_table
- Add backend endpoints for get/set language

**UI Features:**
- Add language switcher dropdown to topbar (🇫🇷 FR / 🇬🇧 EN)
- Auto-sync language selection across all pages
- Support for static HTML and dynamically created elements

**Implementation:**
- Migrate sensors.html as working example
- Add data-i18n attributes to all UI elements
- Support for buttons, inputs, and dynamic content
- Comprehensive README documentation in html/lang/

**Technical Details:**
- Works completely offline (local JSON files)
- No external dependencies
- Database-backed user preference
- Event-based language change notifications
- Automatic translation on page load

Next steps: Gradually migrate other pages (admin, wifi, index, etc.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-01-05 18:10:06 +01:00
parent 906eaa851d
commit 163d60bf34
8 changed files with 561 additions and 24 deletions

View File

@@ -77,6 +77,46 @@ if ($type == "get_config_sqlite") {
}
}
// GET language preference from SQLite
if ($type == "get_language") {
try {
$db = new PDO("sqlite:$database_path");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT value FROM config_table WHERE key = 'language'");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$language = $result ? $result['value'] : 'fr'; // Default to French
echo json_encode(['language' => $language]);
} catch (Exception $e) {
echo json_encode(['language' => 'fr', 'error' => $e->getMessage()]);
}
}
// SET language preference in SQLite
if ($type == "set_language") {
$language = $_GET['language'];
// Validate language (only allow fr or en)
if (!in_array($language, ['fr', 'en'])) {
echo json_encode(['success' => false, 'error' => 'Invalid language']);
exit;
}
try {
$db = new PDO("sqlite:$database_path");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("UPDATE config_table SET value = ? WHERE key = 'language'");
$stmt->execute([$language]);
echo json_encode(['success' => true, 'language' => $language]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
}
/*
*/