Skip to content

Commit

Permalink
refactor(core): move LocaleContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent 79e4bfa commit d614474
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {type i18n} from 'i18next'
import type {i18n} from 'i18next'
import {createContext} from 'react'

import {type Locale} from './types'

/**
* @internal
* @hidden
*/
export const LocaleContext = createContext<LocaleContextValue | undefined>(undefined)
import type {Locale} from 'sanity'

/**
* @internal
Expand All @@ -19,3 +12,9 @@ export interface LocaleContextValue {
__internal: {i18next: i18n}
changeLocale: (newLocale: string) => Promise<void>
}

/**
* @internal
* @hidden
*/
export const LocaleContext = createContext<LocaleContextValue | undefined>(undefined)
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './form/studio/PresenceContext'
export * from './form/studio/ReferenceInputOptionsContext'
export * from './form/studio/reviewChanges/ReviewChangesContext'
export * from './form/studio/ValidationContext'
export * from './i18n/LocaleContext'
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {type i18n} from 'i18next'
import {type PropsWithChildren, Suspense, useCallback, useMemo, useSyncExternalStore} from 'react'
import {I18nextProvider} from 'react-i18next'
import {LocaleContext, type LocaleContextValue} from 'sanity/_singletons'

import {LoadingBlock} from '../../components/loadingBlock'
import {useSource} from '../../studio'
import {LocaleContext, type LocaleContextValue} from '../LocaleContext'
import {defaultLocale} from '../locales'
import {storePreferredLocale} from '../localeStore'
import {type Locale} from '../types'
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/i18n/hooks/useLocale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useContext} from 'react'
import {LocaleContext, type LocaleContextValue} from 'sanity/_singletons'

import {LocaleContext, type LocaleContextValue} from '../LocaleContext'
import {type Locale} from '../types'

/**
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './locales'
export * from './Translate'
export type {
ImplicitLocaleResourceBundle,
Locale,
LocaleConfigContext,
LocaleDefinition,
LocaleNestedResource,
Expand Down

0 comments on commit d614474

Please sign in to comment.