# gt-next: General Translation Next.js SDK: useLocale URL: https://generaltranslation.com/en-US/docs/next/api/helpers/use-locale.mdx --- title: useLocale description: API reference for the useLocale hook --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Overview The `useLocale` hook retrieves the user's current locale from the [`` context](/docs/next/api/components/gtprovider). The locale is returned as a BCP 47 [locale code](/docs/core/locales), e.g., `'en-US'`. `useLocale` is a client-side hook and *can only be used on client-side components*. Ensure your app is wrapped in a [``](/docs/next/api/components/gtprovider). ## Reference ### Returns A string representing the user's current locale, e.g., `'en-US'`. --- ## Fallback behavior When an unsupported locale is requested, a fallback locale will be selected. For instance, in the event of an unsupported locale, if (1) the user has configured multiple preferred locales in their browser settings, and (2) one of these locales is supported by your application, then the locale will fallback to the best language. Additionally, if no possible fallback locales are available, but two locales share the same language (e.g., `en-US` and `en-GB`), then the locale will fallback to the supported locale that shares the same language. If neither condition can be met, then the default locale will be used. See [`gt.config.json`](/docs/next/api/config/gt-config-json) docs for information on configuring supported locales. --- ## Examples ### Basic usage Retrieve the current locale and display it in your component. ```jsx title="CurrentLocale.jsx" copy 'use client'; import { useLocale } from 'gt-next'; export default function CurrentLocale() { const locale = useLocale(); // [!code highlight] return

Current locale: {locale}

; } ``` --- ## Notes - The `useLocale` hook relies on the [``](/docs/next/api/components/gtprovider) to access the context. Ensure your app is wrapped with a provider at the root level. - `useLocale` is client-side only. - Learn more about locale codes [here](/docs/core/locales). ## Next steps - Learn how to manage and specify supported locales in your application with the [`gt.config.json`](/docs/next/api/config/gt-config-json) file.