Add English language support with i18n implementation

Implemented comprehensive internationalization (i18n) for both frontend and backend:

Frontend:
- Added react-i18next configuration with Spanish (default) and English
- Created translation files (locales/es.json, locales/en.json)
- Refactored core components to use i18n: LoginPage, DashboardHeader, DataUploader
- Created LanguageSelector component with toggle between ES/EN
- Updated API client to send Accept-Language header

Backend:
- Created i18n module with translation dictionary for error messages
- Updated security.py to return localized authentication errors
- Updated api/analysis.py to return localized validation errors
- Implemented language detection from Accept-Language header

Spanish remains the default language ensuring backward compatibility.
Users can switch between languages using the language selector in the dashboard header.

https://claude.ai/code/session_1N9VX
This commit is contained in:
Claude
2026-02-06 17:46:01 +00:00
parent 9457d3d02f
commit f719d181c0
15 changed files with 768 additions and 58 deletions

View File

@@ -3,9 +3,11 @@ import React, { useState } from 'react';
import { motion } from 'framer-motion';
import { Lock, User } from 'lucide-react';
import toast from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
import { useAuth } from '../utils/AuthContext';
const LoginPage: React.FC = () => {
const { t } = useTranslation();
const { login } = useAuth();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
@@ -14,14 +16,14 @@ const LoginPage: React.FC = () => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!username || !password) {
toast.error('Introduce usuario y contraseña');
toast.error(t('auth.credentialsRequired'));
return;
}
setIsSubmitting(true);
try {
await login(username, password);
toast.success('Sesión iniciada');
await login(username, password);
toast.success(t('auth.sessionStarted'));
} catch (err) {
console.error('Error en login', err);
const msg =
@@ -48,14 +50,14 @@ const LoginPage: React.FC = () => {
Beyond Diagnostic
</h1>
<p className="text-sm text-slate-500">
Inicia sesión para acceder al análisis
{t('auth.loginTitle')}
</p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-1">
<label className="block text-sm font-medium text-slate-700">
Usuario
{t('auth.username')}
</label>
<div className="relative">
<span className="absolute inset-y-0 left-0 pl-3 flex items-center text-slate-400">
@@ -73,7 +75,7 @@ const LoginPage: React.FC = () => {
<div className="space-y-1">
<label className="block text-sm font-medium text-slate-700">
Contraseña
{t('auth.password')}
</label>
<div className="relative">
<span className="absolute inset-y-0 left-0 pl-3 flex items-center text-slate-400">
@@ -94,11 +96,11 @@ const LoginPage: React.FC = () => {
disabled={isSubmitting}
className="w-full inline-flex items-center justify-center rounded-2xl bg-indigo-600 text-white text-sm font-medium py-2.5 shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-60 disabled:cursor-not-allowed"
>
{isSubmitting ? 'Entrando…' : 'Entrar'}
{isSubmitting ? t('auth.enteringButton') : t('auth.enterButton')}
</button>
<p className="text-[11px] text-slate-400 text-center mt-2">
La sesión permanecerá activa durante 1 hora.
{t('auth.sessionInfo')}
</p>
</form>
</motion.div>