Helpers

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 in server-side components.

See withGTConfig for configuration. If no default locale is specified in withGTConfig, it defaults to 'en-US'. For the 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

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

Next steps

How is this guide?

getDefaultLocale