diff --git a/astro.config.mjs b/astro.config.mjs index 0758b46..6ba1f0d 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -7,10 +7,17 @@ import tailwind from "@astrojs/tailwind"; // https://astro.build/config export default defineConfig({ integrations: [react(), tailwind()], - output: "hybrid", + output: "server", //El output server es necesario para que i18n funcione, para mas info mirar la documentacion del mismo adapter: cloudflare({ }), image: { domains: ["yellowumbrella.dev"], + }, + i18n: { + locales: ["es", "en"], + defaultLocale: "es", + routing: { + prefixDefaultLocale: true + } } }); \ No newline at end of file diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx index af28291..f05899a 100644 --- a/src/components/ContactForm.tsx +++ b/src/components/ContactForm.tsx @@ -4,6 +4,7 @@ import PhoneInput, { isValidPhoneNumber } from "react-phone-number-input"; import { Turnstile } from "@marsidev/react-turnstile"; import type { TurnstileInstance } from "@marsidev/react-turnstile"; import "react-phone-number-input/style.css"; +import { useTranslationsReact, getLangFromUrlReact } from '../i18n/react-utils'; type FormInputs = { empresa: string; @@ -13,8 +14,15 @@ type FormInputs = { mensaje: string; }; +interface ContactFormProps { + lang?: string; +} -export default function ContactForm() { +export default function ContactForm({ lang }: ContactFormProps = {}) { + // Detectar idioma desde la URL del navegador si no se proporciona + const currentLang = lang || getLangFromUrlReact(window.location.pathname); + const t = useTranslationsReact(currentLang as 'es' | 'en'); + const { register, handleSubmit, @@ -42,7 +50,7 @@ export default function ContactForm() { } if (!token) { - setStatus({ type: "error", message: "Por favor, completa el captcha antes de enviar" }); + setStatus({ type: "error", message: t('contact.form.captcha.required') }); return; } @@ -65,7 +73,7 @@ export default function ContactForm() { if (!res.ok) { const text = await res.text(); - throw new Error(text || "Error al enviar el formulario"); + throw new Error(text || t('contact.form.error')); } setStatus({ type: "success" }); @@ -75,7 +83,7 @@ export default function ContactForm() { // Reset Turnstile widget using ref turnstileRef.current?.reset(); } catch (err: unknown) { - setStatus({ type: "error", message: (err instanceof Error ? err.message : String(err)) || "Error inesperado" }); + setStatus({ type: "error", message: (err instanceof Error ? err.message : String(err)) || t('contact.form.error') }); } }; @@ -89,72 +97,72 @@ export default function ContactForm() { >
{errors.empresa && ( -

Este campo es obligatorio

+

{t('contact.form.company.required')}

)}
{errors.nombreCompleto && ( -

Introduce tu nombre completo

+

{t('contact.form.name.required')}

)}
{errors.email && ( -

Introduce un email válido

+

{t('contact.form.email.required')}

)}
- +
{telefono && typeof telefono === "string" && !isValidPhoneNumber(telefono) && (

- El número puede no ser válido. Revisa el país y formato. + {t('contact.form.phone.invalid')}

)}