Bluesky app fork with some witchin' additions 馃挮
at main 32 lines 929 B view raw
1import {createContext, useContext} from 'react' 2import {i18n} from '@lingui/core' 3import {I18nProvider as DefaultI18nProvider} from '@lingui/react' 4import {type Locale} from 'date-fns' 5import type React from 'react' 6 7import {useLocaleLanguage} from './i18n' 8 9const DateLocaleContext = createContext<Locale | undefined>(undefined) 10DateLocaleContext.displayName = 'DateLocaleContext' 11 12export default function I18nProvider({children}: {children: React.ReactNode}) { 13 const dateLocale = useLocaleLanguage() 14 return ( 15 <DateLocaleContext value={dateLocale}> 16 <DefaultI18nProvider i18n={i18n}>{children}</DefaultI18nProvider> 17 </DateLocaleContext> 18 ) 19} 20 21/** 22 * Returns a `date-fns` locale corresponding to the current app language 23 */ 24export function useDateLocale() { 25 const ctx = useContext(DateLocaleContext) 26 27 if (!ctx) { 28 throw new Error('useDateLocale must be used within an I18nProvider') 29 } 30 31 return ctx 32}