General Translation  
Next.jsHelpers

getDefaultLocale()

API Reference for the getDefaultLocale server-side method

Overview

The getDefaultLocale() function retrieves the application's default locale. This locale is determined when the server starts and is used as the fallback language for translations. It returns a locale string, e.g., 'en-US'.

getDefaultLocale() is a server-side method and can only be used on server-side components.

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

Reference

Returns

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


Examples

Basic Usage

Retrieve the application's default locale and use it in your server-side logic.

GetDefaultLocale.jsx
import getDefaultLocale from 'gt-next/server';
 
export default function GetDefaultLocale() {
    const defaultLocale = getDefaultLocale(); 
    return <p>Default locale: {defaultLocale}</p>;
}

Notes

  • The getDefaultLocale() returns the default locale set in initGT().
  • getDefaultLocale() is server-side only.
  • The returned locale adheres to the locale strings format.

Next Steps

On this page