Next.js
Helper functions
Because of recent changes to Next.js which make getting headers asynchronous, getLocale()
must be an asynchronous function.
Server-side helpers
getLocale()
getLocale()
is an asynchronous function which retrieves the user's current language as an ISO-639 language code.
getDefaultLocale()
getDefaultLocale()
is a synchronous function which retrieves your application's default language as an ISO-639 language code.
Client-side helpers
If you want to access the user's locale on the client, you can import the useLocale()
from gt-next/client
. To access the app's default locale, use useDefaultLocale()
.
useLocale()
and useDefaultLocale()
are client-side React hooks. They will throw errors if used in a server component or outside of a <GTProvider>
.