refinedev/refine · error · Error
useGetLocale cannot be called without i18n provider being de
Error message
useGetLocale cannot be called without i18n provider being defined.
What it means
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.
Source
Thrown at packages/core/src/hooks/i18n/useGetLocale.ts:17
import { useCallback, useContext } from "react";
import { I18nContext } from "@contexts/i18n";
export type UseGetLocaleType = () => () => string;
/**
* If you need to know the current locale, refine provides the `useGetLocale` hook.
* It returns the `getLocale` method from `i18nProvider` under the hood.
*
* @see {@link https://refine.dev/docs/api-reference/core/hooks/translate/useGetLocale} for more details.
*/
export const useGetLocale: UseGetLocaleType = () => {
const { i18nProvider } = useContext(I18nContext);
if (!i18nProvider) {
throw new Error(
"useGetLocale cannot be called without i18n provider being defined.",
);
}
return useCallback(() => i18nProvider.getLocale(), []);
};
View on GitHub (pinned to 779d52a20e)
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
Example fix
// before
<Refine>{/* uses useGetLocale somewhere */}</Refine>
// after
import { useTranslation } from 'react-i18next';
<Refine i18nProvider={i18nProvider}>{/* ... */}</Refine> Defensive patterns
Strategy: validation
Validate before calling
const hasI18n = !!useContext(I18nContext)?.i18nProvider; // or check your <Refine> props if (!hasI18n) return <Fallback />;
Prevention
- Always pass i18nProvider to <Refine> when any component uses i18n hooks
- Mock providers in tests/stories for components using useGetLocale/useTranslate
When it happens
Trigger: Calling useGetLocale() in a component rendered outside a <Refine i18nProvider={...}> tree, or rendering the component before the provider is mounted.
Common situations: 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.
Related errors
- Not implemented custom on data provider.
- Not implemented custom on data provider.
- Invalid action type
- If you use `useDataGrid` hook, you need to use `DataGrid` el
- Unsupported properties are found in `routerProvider` prop. Y
AI-assisted analysis of refinedev/refine@779d52a20e (2026-08-27).
Data as JSON: /api/errors/eddacb4883819fe7.
Report an issue: GitHub.