2025-12-25 21:50:34 +01:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { NextIntlClientProvider } from "next-intl";
|
|
|
|
|
import { ReactNode, useMemo } from "react";
|
|
|
|
|
import { useLanguage } from "../hooks/useLanguage";
|
|
|
|
|
|
|
|
|
|
// Import all locale messages
|
|
|
|
|
import esCommon from "../../locales/es/common.json";
|
|
|
|
|
import enCommon from "../../locales/en/common.json";
|
|
|
|
|
import caCommon from "../../locales/ca/common.json";
|
2025-12-25 22:06:39 +01:00
|
|
|
import esNavigation from "../../locales/es/navigation.json";
|
|
|
|
|
import enNavigation from "../../locales/en/navigation.json";
|
|
|
|
|
import caNavigation from "../../locales/ca/navigation.json";
|
|
|
|
|
import esExchange from "../../locales/es/exchange.json";
|
|
|
|
|
import enExchange from "../../locales/en/exchange.json";
|
|
|
|
|
import caExchange from "../../locales/ca/exchange.json";
|
2025-12-25 21:50:34 +01:00
|
|
|
|
|
|
|
|
const messages = {
|
2025-12-25 22:06:39 +01:00
|
|
|
es: { common: esCommon, navigation: esNavigation, exchange: esExchange },
|
|
|
|
|
en: { common: enCommon, navigation: enNavigation, exchange: enExchange },
|
|
|
|
|
ca: { common: caCommon, navigation: caNavigation, exchange: caExchange },
|
2025-12-25 21:50:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface IntlProviderProps {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function IntlProvider({ children }: IntlProviderProps) {
|
|
|
|
|
const { locale } = useLanguage();
|
|
|
|
|
|
|
|
|
|
const localeMessages = useMemo(() => {
|
|
|
|
|
return messages[locale] || messages.es;
|
|
|
|
|
}, [locale]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<NextIntlClientProvider locale={locale} messages={localeMessages}>
|
|
|
|
|
{children}
|
|
|
|
|
</NextIntlClientProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|