{"record":{"id":"eddacb4883819fe7","repo":"refinedev/refine","slug":"usegetlocale-cannot-be-called-without-i18n-provide","errorCode":null,"errorMessage":"useGetLocale cannot be called without i18n provider being defined.","messagePattern":"useGetLocale cannot be called without i18n provider being defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/hooks/i18n/useGetLocale.ts","lineNumber":17,"sourceCode":"import { useCallback, useContext } from \"react\";\n\nimport { I18nContext } from \"@contexts/i18n\";\n\nexport type UseGetLocaleType = () => () => string;\n\n/**\n * If you need to know the current locale, refine provides the `useGetLocale` hook.\n * It returns the `getLocale` method from `i18nProvider` under the hood.\n *\n * @see {@link https://refine.dev/docs/api-reference/core/hooks/translate/useGetLocale} for more details.\n */\nexport const useGetLocale: UseGetLocaleType = () => {\n  const { i18nProvider } = useContext(I18nContext);\n\n  if (!i18nProvider) {\n    throw new Error(\n      \"useGetLocale cannot be called without i18n provider being defined.\",\n    );\n  }\n\n  return useCallback(() => i18nProvider.getLocale(), []);\n};\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/refinedev/refine/blob/779d52a20e29b0307ac0df04d135beba434370dc/packages/core/src/hooks/i18n/useGetLocale.ts#L1-L24","documentation":"useGetLocale reads the i18nProvider from I18nContext; if the app was not wrapped in <Refine> with an i18nProvider (or the context is otherwise absent) there is no getLocale to return, so the hook throws.","triggerScenarios":"Calling useGetLocale() in a component rendered outside a <Refine i18nProvider={...}> tree, or rendering the component before the provider is mounted.","commonSituations":"Adding i18n-dependent components (language switchers) before wiring an i18nProvider; unit tests rendering the component without Refine wrappers; extracting components into a storybook without providers.","solutions":["Pass an i18nProvider to <Refine i18nProvider={...}>","Wrap the component tree with the Refine component that supplies I18nContext","In tests/stories, provide a minimal i18nProvider mock"],"exampleFix":"// before\n<Refine>{/* uses useGetLocale somewhere */}</Refine>\n// after\nimport { useTranslation } from 'react-i18next';\n<Refine i18nProvider={i18nProvider}>{/* ... */}</Refine>","handlingStrategy":"validation","validationCode":"const hasI18n = !!useContext(I18nContext)?.i18nProvider; // or check your <Refine> props\nif (!hasI18n) return <Fallback />;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass i18nProvider to <Refine> when any component uses i18n hooks","Mock providers in tests/stories for components using useGetLocale/useTranslate"],"tags":["refine","i18n","react-context","hooks"],"backgroundTag":"missing-context-provider","analyzedSha":"779d52a20e29b0307ac0df04d135beba434370dc","analyzedAt":"2026-08-27T11:15:25.854Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}