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 withGTConfig for configuration.
If no default locale is specified in withGTConfig 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.
import getDefaultLocale from 'gt-next/server';
export default function GetDefaultLocale() {
const defaultLocale = getDefaultLocale();
return <p>Default locale: {defaultLocale}</p>;
}Notes
- The
getDefaultLocalereturns the default locale set inwithGTConfig. getDefaultLocaleis server-side only.- The returned locale adheres to the locale strings format.
Next Steps
How is this guide?