# gt-next: General Translation Next.js SDK: useLocale URL: https://generaltranslation.com/en-GB/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 behaviour When an unsupported locale is requested, a fallback locale is selected. For example, if an unsupported locale is requested, and (1) the user has configured multiple preferred locales in their browser settings, and (2) one of those locales is supported by your application, then the locale will fall back to the best matching language. Additionally, if no fallback locales are available, but two locales share the same language (for example, `en-US` and `en-GB`), then the locale will fall back to the supported locale that shares that language. If neither condition is met, the default locale will be used. See the [`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 the supported locales in your application using the [`gt.config.json`](/docs/next/api/config/gt-config-json) file.