# node: getRequestLocale
URL: https://generaltranslation.com/en-US/docs/node/api/get-request-locale.mdx
---
title: getRequestLocale
description: API reference for the getRequestLocale function
---
## Overview
The `getRequestLocale` function extracts the preferred locale from a request's `Accept-Language` header and matches it against your configured locales.
```js
import { getRequestLocale } from 'gt-node';
const locale = getRequestLocale(req); // 'fr'
```
**Requires initialization:**
Call [`initializeGT`](/docs/node/api/initialize-gt) before using `getRequestLocale` so it knows which locales are supported.
## Reference
### Parameters
.',
optional: false,
},
}}
/>
### Returns
`string` — The best matching BCP 47 [locale code](/docs/core/locales) from your configured locales, or the `defaultLocale` if no match is found.
---
## Examples
### Express middleware
```js title="middleware/locale.js"
import { withGT, getRequestLocale } from 'gt-node';
export function localeMiddleware(req, res, next) {
const locale = getRequestLocale(req);
withGT(locale, () => next());
}
```
### Combining with other strategies
Use `getRequestLocale` as a fallback when no explicit preference is set:
```js title="middleware/locale.js"
import { withGT, getRequestLocale } from 'gt-node';
export function localeMiddleware(req, res, next) {
const locale =
req.query.lang ||
req.cookies?.locale ||
getRequestLocale(req);
withGT(locale, () => next());
}
```
---
## Next steps
- See [`getLocale`](/docs/node/api/get-locale) to read the locale inside a `withGT` context.
- See the [Locale Detection & Middleware](/docs/node/guides/middleware) guide for full middleware patterns.