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

  1. Pass an i18nProvider to <Refine i18nProvider={...}>
  2. Wrap the component tree with the Refine component that supplies I18nContext
  3. 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

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


AI-assisted analysis of refinedev/refine@779d52a20e (2026-08-27). Data as JSON: /api/errors/eddacb4883819fe7. Report an issue: GitHub.