General Translation  
Next.jsHelpers

useDefaultLocale()

API Reference for the useDefaultLocale hook

Overview

The useDefaultLocale hook retrieves the application's default locale from the <GTProvider> context. This locale represents the fallback language for your app and is typically used when a user's preferred locale is unavailable.

useDefaultLocale is a client-side hook and can only be used on client-side components. Ensure your app is wrapped in a <GTProvider>.

See initGT() for configuration. If no default locale is specified in initGT() it defaults to 'en-US'. For server-side, see getDefaultLocale().

Reference

Returns

A string representing the application's default locale, e.g., 'en-US'.


Examples

Basic Usage

Retrieve the application's default locale and display it in your component.

DefaultLocale.jsx
"use client";
import { useDefaultLocale } from 'gt-next/client';
 
export default function DefaultLocale() {
    const defaultLocale = useDefaultLocale();
 
    return <p>Default locale: {defaultLocale}</p>; // Display the default locale
}

Notes

  • The useDefaultLocale() hook relies on the <GTProvider> to access the context. Ensure your app is wrapped with a provider at the root level.
  • useDefaultLocale() is client-side only.
  • Learn more about locale strings here.

Next Steps

On this page