import {createContext, useContext} from 'react' import {i18n} from '@lingui/core' import {I18nProvider as DefaultI18nProvider} from '@lingui/react' import {type Locale} from 'date-fns' import type React from 'react' import {useLocaleLanguage} from './i18n' const DateLocaleContext = createContext(undefined) DateLocaleContext.displayName = 'DateLocaleContext' export default function I18nProvider({children}: {children: React.ReactNode}) { const dateLocale = useLocaleLanguage() return ( {children} ) } /** * Returns a `date-fns` locale corresponding to the current app language */ export function useDateLocale() { const ctx = useContext(DateLocaleContext) if (!ctx) { throw new Error('useDateLocale must be used within an I18nProvider') } return ctx }