import { useMemo } from 'react'
import { I18nextProvider, useTranslation } from 'react-i18next'
import { FormatContext } from './context.js'
import { createFormatters } from './format.js'
import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE } from './locale.js'
/**
* Put translations and venue formatting into the tree. `venue` is bootstrap.venue
* ({ timezone, currency, … }); until it's loaded the defaults (Europe/Athens, EUR) apply.
* Formatters follow the current language live.
*/
export function I18nProvider({ i18n, venue, children }) {
return (
{children}
)
}
function Formats({ venue, children }) {
const { i18n } = useTranslation()
const language = i18n.resolvedLanguage || i18n.language
const timeZone = venue?.timezone || DEFAULT_TIMEZONE
const currency = venue?.currency || DEFAULT_CURRENCY
const value = useMemo(() => createFormatters({ language, timeZone, currency }), [language, timeZone, currency])
return {children}
}