فهرست منبع

feat: add gettext for English translations in error and logs templates

Manuel 7 ماه پیش
والد
کامیت
e09b5e9e30
3فایلهای تغییر یافته به همراه196 افزوده شده و 197 حذف شده
  1. 3 4
      templates/error.html
  2. 191 191
      templates/index.html
  3. 2 2
      templates/logsView.html

+ 3 - 4
templates/error.html

@@ -3,7 +3,7 @@
   <head>
     <meta charset="UTF-8" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>Error - Squid Monitor</title>
+    <title>{{ _("Error - Squid Monitor") }}</title>
     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
     <style>
       body {
@@ -42,10 +42,9 @@
       </div>
       <h1 class="error-message">{{ message }}</h1>
       <p>
-        Disculpamos las molestias. Por favor, intenta de nuevo más tarde o
-        contacta al soporte si el problema persiste.
+        {{ _("Disculpamos las molestias. Por favor, intenta de nuevo más tarde o contacta al soporte si el problema persiste.") }}
       </p>
-      <a href="/" class="btn btn-primary btn-home">Volver al Inicio</a>
+      <a href="/" class="btn btn-primary btn-home">{{ _("Volver al Inicio") }}</a>
     </div>
 
     <!-- Bootstrap JS and Icons -->

+ 191 - 191
templates/index.html

@@ -1,192 +1,192 @@
-{% extends 'layouts/base.html' %} 
-
-{% from 'macros.html' import format_bandwidth %}
-
-{% set valid_users = {} %} 
-{% for user, user_data in grouped_connections.items()%} 
-  {% if user and user != "-" and user != "Anónimo" %} 
-    {% set _ = valid_users.update({user: user_data}) %} 
-  {% endif %} 
-{% endfor %}
-
-{% block header %}
-  <!-- CONTAINER ALIGNED WITH THE REST OF THE CONTENT -->
-  <div class="max-w-7xl mx-auto">
-    <div class="flex flex-wrap items-center gap-3 mb-4 bg-white/70 dark:bg-gray-800/60 px-3 py-2 rounded-md border border-gray-200 shadow-sm text-sm w-full">
-      <label for="refresh-interval" class="text-gray-700 dark:text-gray-200 font-medium select-none">⏱️</label>
-      <div class="flex items-center gap-1">
-        <input id="refresh-interval" type="number" min="10" class="w-20 px-2 py-1 border border-gray-300 dark:border-gray-600 rounded focus:ring-1 focus:ring-blue-500 focus:outline-none bg-white/80 dark:bg-gray-700/60 text-gray-700 dark:text-gray-100" placeholder="60" aria-label="Intervalo de refresco (segundos)">
-        <span class="text-gray-500 dark:text-gray-400">s</span>
-      </div>
-      <div class="flex items-center gap-1 text-gray-600 dark:text-gray-300">
-        <span class="hidden sm:inline">→</span>
-        <span id="next-refresh" class="font-mono">--</span>
-      </div>
-      <button id="set-interval-btn" class="px-3 py-1 rounded bg-blue-600 hover:bg-blue-700 text-white font-medium transition text-xs">Aplicar</button>
-      <span id="persist-status" class="text-[11px] text-gray-400 ml-auto pr-1 opacity-0 transition-opacity"></span>
-    </div>
-  </div>
-{% endblock header %}
-
-{% block content %}
-<div id="datos-conexiones" class="w-full">
-  {% include 'partials/conexiones.html' %}
-</div>
-{% endblock %}
-
-{% block scripts %}
-  <script src="{{ url_for('static', filename='js/conexiones.js') }}"></script>
-  <script>
-    let isDetailedView = true;
-
-    function applyViewState() {
-      const contents = document.querySelectorAll("[data-accordion-content]");
-      const icons = document.querySelectorAll(".user-accordion .fa-chevron-down");
-      const toggleAllButton = document.getElementById("toggle-all-button");
-
-      if (contents.length === 0 || !toggleAllButton) return;
-
-      if (isDetailedView) {
-        contents.forEach((content) => content.style.display = '');
-        icons.forEach((icon) => icon.classList.add("rotate-180"));
-        toggleAllButton.textContent = "Ver Resumen";
-      } else {
-        contents.forEach((content) => content.style.display = 'none');
-        icons.forEach((icon) => icon.classList.remove("rotate-180"));
-        toggleAllButton.textContent = "Ver Detalles";
-      }
-    }
-
-    function setupSummaryButton() {
-      const toggleAllButton = document.getElementById("toggle-all-button");
-      if (!toggleAllButton) return;
-
-      const newButton = toggleAllButton.cloneNode(true);
-      toggleAllButton.parentNode.replaceChild(newButton, toggleAllButton);
-
-      newButton.addEventListener("click", () => {
-        isDetailedView = !isDetailedView; 
-        applyViewState(); 
-      });
-    }
-
-    async function refrescarConexiones() {
-      try {
-        // CAMBIO: Usar la ruta principal con parámetro partial en lugar de ruta separada
-        const response = await fetch("/?partial=true");
-        if (!response.ok) throw new Error("Respuesta no OK");
-
-        const html = await response.text();
-        const container = document.getElementById("datos-conexiones");
-        container.innerHTML = html;
-
-        setupSummaryButton();
-        applyViewState();
-        // Restaurar el estado individual de los acordeones después de aplicar la vista global
-        if (window.restoreAccordionState) window.restoreAccordionState();
-      } catch (error) {
-        console.error("Error al actualizar conexiones:", error);
-      }
-    }
-
-    const REFRESH_KEY = 'squidstats.refreshIntervalSec';
-    const VIEW_KEY = 'squidstats.viewMode';
-    let refreshInterval = 60000; // ms
-    let refreshTimer = null;
-    let countdownTimer = null;
-    let secondsLeft = 0;
-
-    function safeGet(key) {
-      try { return localStorage.getItem(key); } catch { return null; }
-    }
-    function safeSet(key, val) {
-      try { localStorage.setItem(key, val); persistStatus('Guardado'); } catch { persistStatus('No se pudo guardar'); }
-    }
-    function persistStatus(msg) {
-      const el = document.getElementById('persist-status');
-      if (!el) return;
-      el.textContent = msg;
-      el.classList.remove('opacity-0');
-      setTimeout(() => { el.classList.add('opacity-0'); }, 1600);
-    }
-
-    function getRefreshIntervalFromStorage() {
-      const stored = safeGet(REFRESH_KEY);
-      const val = parseInt(stored);
-      return (!isNaN(val) && val >= 5) ? val : 60;
-    }
-    function setRefreshIntervalToStorage(val) { safeSet(REFRESH_KEY, String(val)); }
-
-    function restoreViewState() {
-      const stored = safeGet(VIEW_KEY);
-      if (stored === 'summary') isDetailedView = false;
-    }
-    function saveViewState() { safeSet(VIEW_KEY, isDetailedView ? 'detailed' : 'summary'); }
-
-    const originalApplyViewState = applyViewState;
-    applyViewState = function() { 
-      originalApplyViewState();
-      saveViewState();
-    };
-
-    function startRefreshTimer() {
-      if (refreshTimer) clearInterval(refreshTimer);
-      if (countdownTimer) clearInterval(countdownTimer);
-      secondsLeft = refreshInterval / 1000;
-      updateCountdown();
-      refreshTimer = setInterval(() => {
-        refrescarConexiones();
-        secondsLeft = refreshInterval / 1000; // reset
-      }, refreshInterval);
-      countdownTimer = setInterval(() => {
-        secondsLeft -= 1;
-        if (secondsLeft < 0) secondsLeft = refreshInterval / 1000;
-        updateCountdown();
-      }, 1000);
-    }
-
-    function updateCountdown() {
-      const el = document.getElementById('next-refresh');
-      if (!el) return;
-      el.textContent = secondsLeft + 's';
-    }
-
-    function applyNewInterval(valSec) {
-      refreshInterval = valSec * 1000;
-      setRefreshIntervalToStorage(valSec);
-      startRefreshTimer();
-    }
-
-    document.addEventListener('DOMContentLoaded', () => {
-      const storedRaw = safeGet(REFRESH_KEY);
-      const intervalValue = getRefreshIntervalFromStorage();
-      document.getElementById('refresh-interval').value = intervalValue;
-      refreshInterval = intervalValue * 1000;
-      if (storedRaw === null) {
-        setRefreshIntervalToStorage(intervalValue);
-        console.debug('[SquidStats] Intervalo por defecto almacenado:', intervalValue, 's');
-      }
-      restoreViewState();
-
-      setupSummaryButton();
-      applyViewState();
-      // Restaurar el estado individual de los acordeones después de aplicar la vista global
-      if (window.restoreAccordionState) window.restoreAccordionState();
-      startRefreshTimer();
-
-      const intervalInput = document.getElementById('refresh-interval');
-      document.getElementById('set-interval-btn').addEventListener('click', () => {
-        const val = parseInt(intervalInput.value);
-        if (!isNaN(val) && val >= 5) {
-          applyNewInterval(val);
-        } else {
-          intervalInput.value = getRefreshIntervalFromStorage();
-        }
-      });
-      intervalInput.addEventListener('change', () => {
-        const val = parseInt(intervalInput.value);
-        if (!isNaN(val) && val >= 5) applyNewInterval(val);
-      });
-    });
-  </script>
+{% extends 'layouts/base.html' %} 
+
+{% from 'macros.html' import format_bandwidth %}
+
+{% set valid_users = {} %} 
+{% for user, user_data in grouped_connections.items()%} 
+  {% if user and user != "-" and user != "Anónimo" %} 
+    {% set _ = valid_users.update({user: user_data}) %} 
+  {% endif %} 
+{% endfor %}
+
+{% block header %}
+  <!-- CONTAINER ALIGNED WITH THE REST OF THE CONTENT -->
+  <div class="max-w-7xl mx-auto">
+    <div class="flex flex-wrap items-center gap-3 mb-4 bg-white/70 dark:bg-gray-800/60 px-3 py-2 rounded-md border border-gray-200 shadow-sm text-sm w-full">
+      <label for="refresh-interval" class="text-gray-700 dark:text-gray-200 font-medium select-none">⏱️</label>
+      <div class="flex items-center gap-1">
+        <input id="refresh-interval" type="number" min="10" class="w-20 px-2 py-1 border border-gray-300 dark:border-gray-600 rounded focus:ring-1 focus:ring-blue-500 focus:outline-none bg-white/80 dark:bg-gray-700/60 text-gray-700 dark:text-gray-100" placeholder="60" aria-label="{{ _("Intervalo de refresco (segundos)") }}">
+        <span class="text-gray-500 dark:text-gray-400">s</span>
+      </div>
+      <div class="flex items-center gap-1 text-gray-600 dark:text-gray-300">
+        <span class="hidden sm:inline">→</span>
+        <span id="next-refresh" class="font-mono">--</span>
+      </div>
+      <button id="set-interval-btn" class="px-3 py-1 rounded bg-blue-600 hover:bg-blue-700 text-white font-medium transition text-xs">{{ _("Aplicar") }}</button>
+      <span id="persist-status" class="text-[11px] text-gray-400 ml-auto pr-1 opacity-0 transition-opacity"></span>
+    </div>
+  </div>
+{% endblock header %}
+
+{% block content %}
+<div id="datos-conexiones" class="w-full">
+  {% include 'partials/conexiones.html' %}
+</div>
+{% endblock %}
+
+{% block scripts %}
+  <script src="{{ url_for('static', filename='js/conexiones.js') }}"></script>
+  <script>
+    let isDetailedView = true;
+
+    function applyViewState() {
+      const contents = document.querySelectorAll("[data-accordion-content]");
+      const icons = document.querySelectorAll(".user-accordion .fa-chevron-down");
+      const toggleAllButton = document.getElementById("toggle-all-button");
+
+      if (contents.length === 0 || !toggleAllButton) return;
+
+      if (isDetailedView) {
+        contents.forEach((content) => content.style.display = '');
+        icons.forEach((icon) => icon.classList.add("rotate-180"));
+        toggleAllButton.textContent = "Ver Resumen";
+      } else {
+        contents.forEach((content) => content.style.display = 'none');
+        icons.forEach((icon) => icon.classList.remove("rotate-180"));
+        toggleAllButton.textContent = "Ver Detalles";
+      }
+    }
+
+    function setupSummaryButton() {
+      const toggleAllButton = document.getElementById("toggle-all-button");
+      if (!toggleAllButton) return;
+
+      const newButton = toggleAllButton.cloneNode(true);
+      toggleAllButton.parentNode.replaceChild(newButton, toggleAllButton);
+
+      newButton.addEventListener("click", () => {
+        isDetailedView = !isDetailedView; 
+        applyViewState(); 
+      });
+    }
+
+    async function refrescarConexiones() {
+      try {
+        // CAMBIO: Usar la ruta principal con parámetro partial en lugar de ruta separada
+        const response = await fetch("/?partial=true");
+        if (!response.ok) throw new Error("Respuesta no OK");
+
+        const html = await response.text();
+        const container = document.getElementById("datos-conexiones");
+        container.innerHTML = html;
+
+        setupSummaryButton();
+        applyViewState();
+        // Restaurar el estado individual de los acordeones después de aplicar la vista global
+        if (window.restoreAccordionState) window.restoreAccordionState();
+      } catch (error) {
+        console.error("Error al actualizar conexiones:", error);
+      }
+    }
+
+    const REFRESH_KEY = 'squidstats.refreshIntervalSec';
+    const VIEW_KEY = 'squidstats.viewMode';
+    let refreshInterval = 60000; // ms
+    let refreshTimer = null;
+    let countdownTimer = null;
+    let secondsLeft = 0;
+
+    function safeGet(key) {
+      try { return localStorage.getItem(key); } catch { return null; }
+    }
+    function safeSet(key, val) {
+      try { localStorage.setItem(key, val); persistStatus('Guardado'); } catch { persistStatus('No se pudo guardar'); }
+    }
+    function persistStatus(msg) {
+      const el = document.getElementById('persist-status');
+      if (!el) return;
+      el.textContent = msg;
+      el.classList.remove('opacity-0');
+      setTimeout(() => { el.classList.add('opacity-0'); }, 1600);
+    }
+
+    function getRefreshIntervalFromStorage() {
+      const stored = safeGet(REFRESH_KEY);
+      const val = parseInt(stored);
+      return (!isNaN(val) && val >= 5) ? val : 60;
+    }
+    function setRefreshIntervalToStorage(val) { safeSet(REFRESH_KEY, String(val)); }
+
+    function restoreViewState() {
+      const stored = safeGet(VIEW_KEY);
+      if (stored === 'summary') isDetailedView = false;
+    }
+    function saveViewState() { safeSet(VIEW_KEY, isDetailedView ? 'detailed' : 'summary'); }
+
+    const originalApplyViewState = applyViewState;
+    applyViewState = function() { 
+      originalApplyViewState();
+      saveViewState();
+    };
+
+    function startRefreshTimer() {
+      if (refreshTimer) clearInterval(refreshTimer);
+      if (countdownTimer) clearInterval(countdownTimer);
+      secondsLeft = refreshInterval / 1000;
+      updateCountdown();
+      refreshTimer = setInterval(() => {
+        refrescarConexiones();
+        secondsLeft = refreshInterval / 1000; // reset
+      }, refreshInterval);
+      countdownTimer = setInterval(() => {
+        secondsLeft -= 1;
+        if (secondsLeft < 0) secondsLeft = refreshInterval / 1000;
+        updateCountdown();
+      }, 1000);
+    }
+
+    function updateCountdown() {
+      const el = document.getElementById('next-refresh');
+      if (!el) return;
+      el.textContent = secondsLeft + 's';
+    }
+
+    function applyNewInterval(valSec) {
+      refreshInterval = valSec * 1000;
+      setRefreshIntervalToStorage(valSec);
+      startRefreshTimer();
+    }
+
+    document.addEventListener('DOMContentLoaded', () => {
+      const storedRaw = safeGet(REFRESH_KEY);
+      const intervalValue = getRefreshIntervalFromStorage();
+      document.getElementById('refresh-interval').value = intervalValue;
+      refreshInterval = intervalValue * 1000;
+      if (storedRaw === null) {
+        setRefreshIntervalToStorage(intervalValue);
+        console.debug('[SquidStats] Intervalo por defecto almacenado:', intervalValue, 's');
+      }
+      restoreViewState();
+
+      setupSummaryButton();
+      applyViewState();
+      // Restaurar el estado individual de los acordeones después de aplicar la vista global
+      if (window.restoreAccordionState) window.restoreAccordionState();
+      startRefreshTimer();
+
+      const intervalInput = document.getElementById('refresh-interval');
+      document.getElementById('set-interval-btn').addEventListener('click', () => {
+        const val = parseInt(intervalInput.value);
+        if (!isNaN(val) && val >= 5) {
+          applyNewInterval(val);
+        } else {
+          intervalInput.value = getRefreshIntervalFromStorage();
+        }
+      });
+      intervalInput.addEventListener('change', () => {
+        const val = parseInt(intervalInput.value);
+        if (!isNaN(val) && val >= 5) applyNewInterval(val);
+      });
+    });
+  </script>
 {% endblock scripts %}

+ 2 - 2
templates/logsView.html

@@ -10,10 +10,10 @@
       </div>
 
       <div class="search-container flex items-center bg-white rounded-[0.5rem] shadow-md overflow-hidden w-[250px] relative">
-        <input type="text" id="username-search" placeholder="Buscar por usuario..." class="search-input w-full pl-4 pr-10 py-3 rounded-[0.5rem] border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-gray-800 h-12"/>
+        <input type="text" id="username-search" placeholder="{{ _("Buscar por usuario...") }}" class="search-input w-full pl-4 pr-10 py-3 rounded-[0.5rem] border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-gray-800 h-12"/>
 
         <!-- Clear search button -->
-        <button id="clear-search" class="absolute right-10 h-full items-center justify-center text-gray-400 hover:text-gray-700 hidden" title="Limpiar búsqueda">
+        <button id="clear-search" class="absolute right-10 h-full items-center justify-center text-gray-400 hover:text-gray-700 hidden" title="{{ _("Limpiar búsqueda") }}">
           <i class="fas fa-times"></i>
         </button>