فهرست منبع

feat: add gettext for error messages in database, LDAP, and notifications services

Manuel 7 ماه پیش
والد
کامیت
01b5f4ef0e
3فایلهای تغییر یافته به همراه9 افزوده شده و 6 حذف شده
  1. 4 3
      services/database/db_info_service.py
  2. 3 2
      services/ldap/ldap_service.py
  3. 2 1
      services/notifications/notifications.py

+ 4 - 3
services/database/db_info_service.py

@@ -4,6 +4,7 @@ from sqlalchemy import text
 from config import Config
 from database.database import get_engine, get_session
 from services.database.admin_helpers import get_all_tables_stats
+from flask_babel import gettext as _
 
 
 def get_tables_info():
@@ -29,7 +30,7 @@ def get_tables_info():
 
     except Exception:
         logger.exception("Error getting database tables")
-        return {"status": "error", "message": "Error interno del servidor"}, 500
+        return {"status": "error", "message": _("Error interno del servidor")}, 500
 
     finally:
         if session:
@@ -146,7 +147,7 @@ def get_db_health():
 
     except Exception:
         logger.exception("Error getting DB health")
-        return {"status": "error", "message": "Error interno del servidor"}, 500
+        return {"status": "error", "message": _("Error interno del servidor")}, 500
 
     finally:
         if session:
@@ -193,7 +194,7 @@ def run_integrity_check():
 
     except Exception:
         logger.exception("Error running integrity check")
-        return {"status": "error", "message": "Error al ejecutar la verificación"}, 500
+        return {"status": "error", "message": _("Error al ejecutar la verificación")}, 500
 
     finally:
         if session:

+ 3 - 2
services/ldap/ldap_service.py

@@ -14,6 +14,7 @@ from ldap3 import (
 )
 from ldap3.utils.conv import escape_filter_chars
 from loguru import logger
+from flask_babel import gettext as _
 
 # ---------------------------------------------------------------------------
 # Internal helpers
@@ -50,7 +51,7 @@ def test_connection(cfg: dict) -> dict:
     try:
         conn = _connect(cfg)
         conn.unbind()
-        return {"status": "success", "message": "Conexión exitosa al servidor LDAP/AD."}
+        return {"status": "success", "message": _("Conexión exitosa al servidor LDAP/AD.")}
     except core.exceptions.LDAPBindError as exc:
         logger.warning(f"LDAP bind falló: {exc}")
         return {"status": "error", "message": f"Error de autenticación: {exc}"}
@@ -186,7 +187,7 @@ def get_user_groups(cfg: dict, username: str) -> dict:
             conn.unbind()
             return {
                 "status": "error",
-                "message": "Usuario no encontrado.",
+                "message": _("Usuario no encontrado."),
                 "groups": [],
                 "user": None,
             }

+ 2 - 1
services/notifications/notifications.py

@@ -8,6 +8,7 @@ from datetime import datetime, timedelta
 from typing import Any
 
 from loguru import logger
+from flask_babel import gettext as _
 from sqlalchemy import and_, desc, func
 from sqlalchemy.orm import Session
 
@@ -298,7 +299,7 @@ def get_default_icon(notification_type):
     icons = {
         "info": "fa-info-circle",
         "warning": "fa-exclamation-triangle",
-        "error": "fa-times-circle",
+        "error": _("fa-times-circle"),
         "success": "fa-check-circle",
     }
     return icons.get(notification_type, "fa-bell")