confluent/ConfluentTranslator/public/index.html
StillHammer 6597ac8cbb Ajout onglet Settings avec configuration globale complète
Nouvel onglet Settings (⚙️) permettant de configurer:

Paramètres globaux:
- Niveau de langue (Proto/Ancien Confluent)
  → S'applique aux traductions et au lexique
  → Supprimé des onglets individuels

Configuration LLM:
- Provider (Anthropic/OpenAI)
- Modèle (avec mise à jour dynamique selon provider)
- Température (slider 0.0-2.0 pour créativité)

Interface:
- Thème clair/sombre avec CSS complet
- Mode verbose (checkbox pour détails)
- Application immédiate du thème

API Keys (optionnel):
- Anthropic API Key
- OpenAI API Key
- Placeholder pour utilisation clés serveur

Fonctionnalités:
- localStorage pour persistance
- Bouton sauvegarde avec message confirmation
- Paramètres appliqués à tous les onglets
- Valeurs par défaut définies

Interface simplifiée: choix de langue retiré des autres onglets
car centralisé dans Settings.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 12:17:57 +08:00

946 lines
29 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ConfluentTranslator</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html {
background: #1a1a1a;
min-height: 100%;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #1a1a1a;
color: #e0e0e0;
padding: 20px;
line-height: 1.6;
min-height: 100vh;
}
.container { max-width: 900px; margin: 0 auto; }
h1 {
text-align: center;
margin-bottom: 30px;
color: #4a9eff;
font-size: 2em;
}
.panel {
background: #2a2a2a;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
border: 1px solid #3a3a3a;
}
.panel h2 {
font-size: 1.2em;
margin-bottom: 15px;
color: #4a9eff;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
color: #b0b0b0;
font-size: 0.9em;
}
select, input, textarea {
width: 100%;
padding: 10px;
background: #1a1a1a;
border: 1px solid #3a3a3a;
border-radius: 4px;
color: #e0e0e0;
font-family: inherit;
}
select option {
background: #1a1a1a;
color: #e0e0e0;
padding: 10px;
}
select:focus {
outline: none;
border-color: #4a9eff;
}
textarea {
resize: vertical;
min-height: 120px;
font-size: 0.95em;
}
button {
background: #4a9eff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
font-weight: 600;
transition: background 0.2s;
}
button:hover { background: #357abd; }
button:disabled { background: #555; cursor: not-allowed; }
.row { display: flex; gap: 15px; }
.row .form-group { flex: 1; }
/* Tabs */
.tabs {
display: flex;
gap: 10px;
margin-bottom: 20px;
border-bottom: 2px solid #3a3a3a;
}
.tab {
background: transparent;
padding: 10px 20px;
border: none;
color: #b0b0b0;
cursor: pointer;
font-weight: 600;
border-bottom: 3px solid transparent;
transition: all 0.2s;
}
.tab:hover { color: #e0e0e0; }
.tab.active {
color: #4a9eff;
border-bottom-color: #4a9eff;
}
.tab-content { display: none; }
.tab-content.active { display: block; }
/* 3 LAYERS SYSTEM */
.layer {
background: #2a2a2a;
border-radius: 8px;
margin-bottom: 15px;
border: 1px solid #3a3a3a;
overflow: hidden;
}
/* Layer 1 - Always visible */
.layer1 {
padding: 20px;
background: #1a1a1a;
border: 2px solid #4a9eff;
}
.layer1-title {
font-size: 0.9em;
color: #4a9eff;
margin-bottom: 10px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
}
.layer1-content {
font-size: 1.3em;
color: #4a9eff;
font-family: 'Courier New', monospace;
line-height: 1.8;
padding: 10px 0;
}
/* Layer 2 & 3 - Collapsible */
.layer-header {
padding: 15px 20px;
background: #2a2a2a;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
transition: background 0.2s;
user-select: none;
}
.layer-header:hover {
background: #333;
}
.layer-title {
font-size: 1em;
font-weight: 600;
display: flex;
align-items: center;
gap: 10px;
}
.layer-icon {
font-size: 1.2em;
}
.layer-arrow {
transition: transform 0.3s;
font-size: 1.2em;
color: #4a9eff;
}
.layer-arrow.expanded {
transform: rotate(180deg);
}
.layer-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out;
background: #1a1a1a;
}
.layer-content.expanded {
max-height: 1000px;
transition: max-height 0.5s ease-in;
}
.layer-content-inner {
padding: 20px;
}
/* Layer 2 specific styles */
.context-item {
margin-bottom: 15px;
}
.context-label {
color: #b0b0b0;
font-size: 0.85em;
margin-bottom: 5px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.word-match {
display: inline-block;
background: #2a2a2a;
padding: 5px 10px;
margin: 3px;
border-radius: 4px;
font-size: 0.9em;
border-left: 3px solid #4a9eff;
}
.word-match-input {
color: #e0e0e0;
}
.word-match-arrow {
color: #4a9eff;
margin: 0 5px;
}
.word-match-output {
color: #4a9eff;
font-family: monospace;
}
.word-match-score {
color: #888;
font-size: 0.85em;
margin-left: 5px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 10px;
margin-top: 10px;
}
.stat-box {
background: #2a2a2a;
padding: 10px;
border-radius: 4px;
border-left: 3px solid #4a9eff;
}
.stat-value {
font-size: 1.5em;
color: #4a9eff;
font-weight: 700;
}
.stat-label {
color: #b0b0b0;
font-size: 0.85em;
}
/* Layer 3 specific styles */
.decomposition-line {
font-family: 'Courier New', monospace;
margin: 5px 0;
padding-left: 10px;
border-left: 2px solid #3a3a3a;
color: #e0e0e0;
}
.notes-text {
color: #b0b0b0;
line-height: 1.8;
}
/* Empty state */
.empty-state {
color: #b0b0b0;
text-align: center;
padding: 30px;
font-style: italic;
}
/* Lexique styles */
.lexique-results {
max-height: 400px;
overflow-y: auto;
margin-top: 15px;
}
.lexique-item {
background: #1a1a1a;
padding: 10px;
margin-bottom: 8px;
border-radius: 4px;
border-left: 3px solid #4a9eff;
display: flex;
justify-content: space-between;
align-items: center;
}
.lexique-fr {
color: #e0e0e0;
font-weight: 500;
}
.lexique-cf {
color: #4a9eff;
font-family: monospace;
font-size: 1.1em;
}
.lexique-count {
color: #b0b0b0;
font-size: 0.9em;
margin-top: 10px;
}
.no-results {
color: #b0b0b0;
text-align: center;
padding: 20px;
font-style: italic;
}
.error { color: #ff4a4a; }
/* Light theme */
body.light-theme {
background: #f5f5f5;
color: #1a1a1a;
}
body.light-theme html {
background: #f5f5f5;
}
body.light-theme h1 {
color: #2563eb;
}
body.light-theme .panel {
background: #ffffff;
border-color: #e5e5e5;
}
body.light-theme .panel h2 {
color: #2563eb;
}
body.light-theme label {
color: #666;
}
body.light-theme select,
body.light-theme input,
body.light-theme textarea {
background: #f9f9f9;
border-color: #e5e5e5;
color: #1a1a1a;
}
body.light-theme select option {
background: #ffffff;
color: #1a1a1a;
}
body.light-theme .tab {
color: #666;
}
body.light-theme .tab.active {
color: #2563eb;
border-bottom-color: #2563eb;
}
body.light-theme .tabs {
border-bottom-color: #e5e5e5;
}
body.light-theme .layer {
background: #ffffff;
border-color: #e5e5e5;
}
body.light-theme .layer1 {
background: #f9f9f9;
border-color: #2563eb;
}
body.light-theme .layer1-title {
color: #2563eb;
}
body.light-theme .layer1-content {
color: #2563eb;
}
body.light-theme .layer-header {
background: #ffffff;
}
body.light-theme .layer-header:hover {
background: #f5f5f5;
}
body.light-theme .layer-content {
background: #f9f9f9;
}
body.light-theme .layer-arrow {
color: #2563eb;
}
body.light-theme .word-match {
background: #ffffff;
border-left-color: #2563eb;
}
body.light-theme .word-match-output {
color: #2563eb;
}
body.light-theme .stat-box {
background: #ffffff;
border-left-color: #2563eb;
}
body.light-theme .stat-value {
color: #2563eb;
}
body.light-theme .lexique-item {
background: #f9f9f9;
border-left-color: #2563eb;
}
body.light-theme .lexique-cf {
color: #2563eb;
}
</style>
</head>
<body>
<div class="container">
<h1>ConfluentTranslator</h1>
<!-- Tabs -->
<div class="tabs">
<button class="tab active" data-tab="traduction">Français → Confluent</button>
<button class="tab" data-tab="cf2fr">Confluent → Français</button>
<button class="tab" data-tab="lexique">Lexique</button>
<button class="tab" data-tab="settings">⚙️ Settings</button>
</div>
<!-- Tab: Traduction Français → Confluent -->
<div id="tab-traduction" class="tab-content active">
<div class="panel">
<h2>Traduction Français → Confluent</h2>
<div class="form-group">
<label>Texte français</label>
<textarea id="input" placeholder="Entrez votre texte en français..."></textarea>
</div>
<button id="translate">Traduire</button>
</div>
<!-- LAYER 1: TRADUCTION (Always visible) -->
<div id="result-container" style="display: none;">
<div class="layer layer1">
<div class="layer1-title">Traduction</div>
<div id="layer1-content" class="layer1-content"></div>
</div>
<!-- LAYER 2: CONTEXTE (Collapsible) -->
<div class="layer">
<div class="layer-header" onclick="toggleLayer('layer2')">
<div class="layer-title">
<span class="layer-icon">📚</span>
<span>Contexte Lexical</span>
</div>
<span class="layer-arrow" id="layer2-arrow"></span>
</div>
<div id="layer2-content" class="layer-content">
<div class="layer-content-inner">
<div class="context-item">
<div class="context-label">Mots trouvés dans le lexique</div>
<div id="layer2-words"></div>
</div>
<div class="context-item">
<div class="context-label">Optimisation</div>
<div class="stats-grid" id="layer2-stats"></div>
</div>
</div>
</div>
</div>
<!-- LAYER 3: EXPLICATIONS LLM (Collapsible) -->
<div class="layer">
<div class="layer-header" onclick="toggleLayer('layer3')">
<div class="layer-title">
<span class="layer-icon">💡</span>
<span>Explications</span>
</div>
<span class="layer-arrow" id="layer3-arrow"></span>
</div>
<div id="layer3-content" class="layer-content">
<div class="layer-content-inner">
<div class="context-item">
<div class="context-label">Décomposition</div>
<div id="layer3-decomposition"></div>
</div>
<div class="context-item" id="layer3-notes-container" style="display: none;">
<div class="context-label">Notes linguistiques</div>
<div id="layer3-notes" class="notes-text"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Tab: Confluent → Français -->
<div id="tab-cf2fr" class="tab-content">
<div class="panel">
<h2>Traduction Confluent → Français</h2>
<div class="form-group">
<label>Texte en Confluent</label>
<textarea id="cf-input" placeholder="Entrez votre texte en Confluent..."></textarea>
</div>
<button id="translate-cf2fr">Traduire</button>
</div>
<!-- Résultat -->
<div id="cf2fr-result-container" style="display: none;">
<div class="layer layer1">
<div class="layer1-title">Traduction brute</div>
<div id="cf2fr-layer1-content" class="layer1-content"></div>
</div>
</div>
</div>
<!-- Tab: Lexique -->
<div id="tab-lexique" class="tab-content">
<div class="panel">
<h2>Recherche dans le lexique</h2>
<div class="form-group">
<label>Rechercher un mot français</label>
<input type="text" id="lexique-search" placeholder="Tapez un mot en français...">
</div>
<div class="lexique-count" id="lexique-count">0 résultat(s)</div>
<div class="lexique-results" id="lexique-results">
<div class="no-results">Commencez à taper pour rechercher...</div>
</div>
</div>
</div>
<!-- Tab: Settings -->
<div id="tab-settings" class="tab-content">
<div class="panel">
<h2>⚙️ Paramètres globaux</h2>
<div class="form-group">
<label>Niveau de langue (global)</label>
<select id="settings-target">
<option value="proto">Proto-Confluent</option>
<option value="ancien">Ancien Confluent</option>
</select>
<small style="color: #888; display: block; margin-top: 5px;">
S'applique aux traductions et recherches dans le lexique
</small>
</div>
<h2 style="margin-top: 30px;">🤖 Configuration LLM</h2>
<div class="row">
<div class="form-group">
<label>Provider</label>
<select id="settings-provider">
<option value="anthropic">Anthropic</option>
<option value="openai">OpenAI</option>
</select>
</div>
<div class="form-group">
<label>Modèle</label>
<select id="settings-model">
<option value="claude-sonnet-4-20250514">Claude Sonnet 4.5 (latest)</option>
<option value="claude-haiku-4-20250514">Claude Haiku 4.5</option>
</select>
</div>
</div>
<div class="form-group">
<label>Température (créativité)</label>
<input type="range" id="settings-temperature" min="0" max="2" step="0.1" value="1.0">
<div style="display: flex; justify-content: space-between; color: #888; font-size: 0.85em;">
<span>Précis (0.0)</span>
<span id="temp-value">1.0</span>
<span>Créatif (2.0)</span>
</div>
</div>
<h2 style="margin-top: 30px;">🎨 Interface</h2>
<div class="form-group">
<label>Thème</label>
<select id="settings-theme">
<option value="dark">Sombre</option>
<option value="light">Clair</option>
</select>
</div>
<div class="form-group">
<label style="display: flex; align-items: center; cursor: pointer;">
<input type="checkbox" id="settings-verbose" style="width: auto; margin-right: 10px;">
<span>Mode verbose (afficher plus de détails)</span>
</label>
</div>
<h2 style="margin-top: 30px;">🔑 API Keys (optionnel)</h2>
<div class="form-group">
<label>Anthropic API Key</label>
<input type="password" id="settings-anthropic-key" placeholder="sk-ant-...">
<small style="color: #888; display: block; margin-top: 5px;">
Laisser vide pour utiliser la clé du serveur
</small>
</div>
<div class="form-group">
<label>OpenAI API Key</label>
<input type="password" id="settings-openai-key" placeholder="sk-...">
<small style="color: #888; display: block; margin-top: 5px;">
Laisser vide pour utiliser la clé du serveur
</small>
</div>
<button onclick="saveSettings()" style="margin-top: 20px;">💾 Sauvegarder les paramètres</button>
<div id="settings-saved-message" style="display: none; color: #4a9eff; margin-top: 10px; font-weight: 600;">
✓ Paramètres sauvegardés !
</div>
</div>
</div>
</div>
<script>
// Lexique data
let lexiqueData = null;
// Load lexique
const loadLexique = async () => {
try {
const response = await fetch('/lexique');
lexiqueData = await response.json();
} catch (error) {
console.error('Error loading lexique:', error);
}
};
// Toggle layer (expand/collapse)
function toggleLayer(layerId) {
const content = document.getElementById(`${layerId}-content`);
const arrow = document.getElementById(`${layerId}-arrow`);
content.classList.toggle('expanded');
arrow.classList.toggle('expanded');
}
// Tab switching
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
tab.classList.add('active');
const tabName = tab.dataset.tab;
document.getElementById(`tab-${tabName}`).classList.add('active');
});
});
// Lexique search
const searchLexique = () => {
const query = document.getElementById('lexique-search').value.toLowerCase().trim();
const settings = JSON.parse(localStorage.getItem('confluentSettings') || '{}');
const niveau = settings.target || 'ancien';
const resultsDiv = document.getElementById('lexique-results');
const countDiv = document.getElementById('lexique-count');
if (!lexiqueData || !lexiqueData.dictionnaire) {
resultsDiv.innerHTML = '<div class="no-results">Lexique en cours de chargement...</div>';
return;
}
if (!query) {
resultsDiv.innerHTML = '<div class="no-results">Commencez à taper pour rechercher...</div>';
countDiv.textContent = '0 résultat(s)';
return;
}
const dict = lexiqueData.dictionnaire;
const results = [];
for (const [key, data] of Object.entries(dict)) {
if (key.includes(query) || (data.mot_francais && data.mot_francais.toLowerCase().includes(query))) {
if (data.is_synonym_of) continue;
const cf = data.traductions && data.traductions.length > 0
? data.traductions[0].confluent
: '?';
results.push({
fr: data.mot_francais || key,
cf: cf,
type: data.traductions?.[0]?.type || '',
domaine: data.traductions?.[0]?.domaine || ''
});
}
}
results.sort((a, b) => {
const aExact = a.fr.toLowerCase() === query;
const bExact = b.fr.toLowerCase() === query;
if (aExact && !bExact) return -1;
if (!aExact && bExact) return 1;
const aStarts = a.fr.toLowerCase().startsWith(query);
const bStarts = b.fr.toLowerCase().startsWith(query);
if (aStarts && !bStarts) return -1;
if (!aStarts && bStarts) return 1;
return a.fr.localeCompare(b.fr);
});
if (results.length === 0) {
resultsDiv.innerHTML = '<div class="no-results">Aucun résultat trouvé</div>';
countDiv.textContent = '0 résultat(s)';
} else {
const html = results.map(r => `
<div class="lexique-item">
<span class="lexique-fr">${r.fr}</span>
<span class="lexique-cf">${r.cf}</span>
</div>
`).join('');
resultsDiv.innerHTML = html;
countDiv.textContent = `${results.length} résultat(s)`;
}
};
document.getElementById('lexique-search').addEventListener('input', searchLexique);
// Settings management
const DEFAULT_SETTINGS = {
target: 'ancien',
provider: 'anthropic',
model: 'claude-sonnet-4-20250514',
temperature: 1.0,
theme: 'dark',
verbose: false,
anthropicKey: '',
openaiKey: ''
};
const loadSettings = () => {
const settings = { ...DEFAULT_SETTINGS, ...JSON.parse(localStorage.getItem('confluentSettings') || '{}') };
// Apply to settings page
document.getElementById('settings-target').value = settings.target;
document.getElementById('settings-provider').value = settings.provider;
document.getElementById('settings-model').value = settings.model;
document.getElementById('settings-temperature').value = settings.temperature;
document.getElementById('temp-value').textContent = settings.temperature;
document.getElementById('settings-theme').value = settings.theme;
document.getElementById('settings-verbose').checked = settings.verbose;
document.getElementById('settings-anthropic-key').value = settings.anthropicKey;
document.getElementById('settings-openai-key').value = settings.openaiKey;
// Apply theme
applyTheme(settings.theme);
// Update model options based on provider
updateModelOptions(settings.provider);
return settings;
};
const saveSettings = () => {
const settings = {
target: document.getElementById('settings-target').value,
provider: document.getElementById('settings-provider').value,
model: document.getElementById('settings-model').value,
temperature: parseFloat(document.getElementById('settings-temperature').value),
theme: document.getElementById('settings-theme').value,
verbose: document.getElementById('settings-verbose').checked,
anthropicKey: document.getElementById('settings-anthropic-key').value,
openaiKey: document.getElementById('settings-openai-key').value
};
localStorage.setItem('confluentSettings', JSON.stringify(settings));
// Apply theme
applyTheme(settings.theme);
// Show saved message
const msg = document.getElementById('settings-saved-message');
msg.style.display = 'block';
setTimeout(() => { msg.style.display = 'none'; }, 2000);
};
const applyTheme = (theme) => {
if (theme === 'light') {
document.body.classList.add('light-theme');
} else {
document.body.classList.remove('light-theme');
}
};
const updateModelOptions = (provider) => {
const modelSelect = document.getElementById('settings-model');
modelSelect.innerHTML = '';
if (provider === 'anthropic') {
modelSelect.innerHTML = `
<option value="claude-sonnet-4-20250514">Claude Sonnet 4.5 (latest)</option>
<option value="claude-haiku-4-20250514">Claude Haiku 4.5</option>
`;
} else if (provider === 'openai') {
modelSelect.innerHTML = `
<option value="chatgpt-4o-latest">ChatGPT-5.1 (latest)</option>
<option value="gpt-4o">GPT-4o</option>
<option value="gpt-4o-mini">GPT-4o Mini</option>
`;
}
};
// Settings event listeners
document.getElementById('settings-provider').addEventListener('change', (e) => {
updateModelOptions(e.target.value);
});
document.getElementById('settings-temperature').addEventListener('input', (e) => {
document.getElementById('temp-value').textContent = e.target.value;
});
// Translation with 3 layers
document.getElementById('translate').addEventListener('click', async () => {
const button = document.getElementById('translate');
const text = document.getElementById('input').value.trim();
const resultContainer = document.getElementById('result-container');
if (!text) {
alert('Veuillez entrer un texte.');
return;
}
button.disabled = true;
resultContainer.style.display = 'none';
// Show loading in layer 1
resultContainer.style.display = 'block';
document.getElementById('layer1-content').textContent = 'Traduction en cours...';
const settings = JSON.parse(localStorage.getItem('confluentSettings') || '{}');
const config = {
text,
target: settings.target || 'ancien',
provider: settings.provider || 'anthropic',
model: settings.model || 'claude-sonnet-4-20250514',
temperature: settings.temperature || 1.0,
};
try {
const response = await fetch('/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config),
});
const data = await response.json();
if (response.ok) {
// LAYER 1: Translation
document.getElementById('layer1-content').textContent = data.layer1.translation;
// LAYER 2: Context
if (data.layer2) {
const wordsHtml = data.layer2.wordsFound && data.layer2.wordsFound.length > 0
? data.layer2.wordsFound.map(w => `
<div class="word-match">
<span class="word-match-input">${w.input}</span>
<span class="word-match-arrow">→</span>
<span class="word-match-output">${w.confluent}</span>
<span class="word-match-score">(${w.score.toFixed(2)})</span>
</div>
`).join('')
: '<div class="no-results">Aucun mot trouvé (fallback racines activé)</div>';
document.getElementById('layer2-words').innerHTML = wordsHtml;
const statsHtml = `
<div class="stat-box">
<div class="stat-value">${data.layer2.entriesUsed || 0}</div>
<div class="stat-label">Entrées utilisées</div>
</div>
<div class="stat-box">
<div class="stat-value">${data.layer2.tokensSaved || 0}</div>
<div class="stat-label">Tokens économisés</div>
</div>
<div class="stat-box">
<div class="stat-value">${data.layer2.savingsPercent || 0}%</div>
<div class="stat-label">Économie</div>
</div>
<div class="stat-box">
<div class="stat-value">${data.layer2.useFallback ? 'OUI' : 'NON'}</div>
<div class="stat-label">Fallback racines</div>
</div>
`;
document.getElementById('layer2-stats').innerHTML = statsHtml;
}
// LAYER 3: Explanations
if (data.layer3) {
const decompHtml = data.layer3.decomposition
? data.layer3.decomposition.split('\n').map(line =>
`<div class="decomposition-line">${line}</div>`
).join('')
: '<div class="no-results">Pas de décomposition disponible</div>';
document.getElementById('layer3-decomposition').innerHTML = decompHtml;
if (data.layer3.notes) {
document.getElementById('layer3-notes').textContent = data.layer3.notes;
document.getElementById('layer3-notes-container').style.display = 'block';
} else {
document.getElementById('layer3-notes-container').style.display = 'none';
}
}
} else {
document.getElementById('layer1-content').innerHTML = `<span class="error">Erreur: ${data.error}</span>`;
}
} catch (error) {
document.getElementById('layer1-content').innerHTML = `<span class="error">Erreur: ${error.message}</span>`;
} finally {
button.disabled = false;
}
});
// Confluent → Français translation
document.getElementById('translate-cf2fr').addEventListener('click', async () => {
const button = document.getElementById('translate-cf2fr');
const text = document.getElementById('cf-input').value.trim();
const resultContainer = document.getElementById('cf2fr-result-container');
if (!text) {
alert('Veuillez entrer un texte en Confluent.');
return;
}
button.disabled = true;
resultContainer.style.display = 'none';
// Show loading
resultContainer.style.display = 'block';
document.getElementById('cf2fr-layer1-content').textContent = 'Traduction en cours...';
try {
const response = await fetch('/api/translate/conf2fr', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text }),
});
const data = await response.json();
if (response.ok) {
document.getElementById('cf2fr-layer1-content').textContent = data.translation || data.result || 'Traduction effectuée';
} else {
document.getElementById('cf2fr-layer1-content').innerHTML = `<span class="error">Erreur: ${data.error}</span>`;
}
} catch (error) {
document.getElementById('cf2fr-layer1-content').innerHTML = `<span class="error">Erreur: ${error.message}</span>`;
} finally {
button.disabled = false;
}
});
// Initialize
loadSettings();
loadLexique();
</script>
</body>
</html>