# gt-node: General Translation Node.js SDK: Detecting the request locale URL: https://generaltranslation.com/en-US/docs/node/guides/detecting-locale.mdx --- title: Detecting the request locale description: How to resolve and bind a locale for each request with General Translation in gt-node. related: links: - /docs/node/guides/translating-strings - /docs/node/guides/configuring - /docs/node/guides/storing-translations --- Every translation call in `gt-node` runs against the current request's locale. You resolve that locale from the request and bind it with [`withGT`](/docs/node/reference/functions/with-gt), so all translation functions downstream use it. ## Bind a locale with `withGT` [#with-gt] Wrap request handling in `withGT(locale, fn)`. It stores the locale for the duration of the request so [`getGT`](/docs/node/reference/functions/get-gt), [`getMessages`](/docs/node/reference/functions/get-messages), [`tx`](/docs/node/reference/functions/tx), and [`getLocale`](/docs/node/reference/functions/get-locale) resolve against it. ```ts import { withGT } from 'gt-node'; app.use((req, res, next) => withGT(resolveLocale(req), () => next())); ``` *Note: Calling a translation or locale function outside a `withGT` scope throws in development; in production it falls back to the default locale.* ## Detect from `Accept-Language` [#accept-language] Use [`getRequestLocale`](/docs/node/reference/functions/get-request-locale) to pick the best supported locale from the request's `Accept-Language` header, falling back to the default locale. ```ts import { withGT, getRequestLocale } from 'gt-node'; app.use((req, res, next) => withGT(getRequestLocale(req), () => next())); ``` ## Detect from your own signals [#custom] To honor an explicit user choice, resolve the locale yourself — for example from a cookie or path segment — and fall back to `getRequestLocale`. Pass the result to `withGT`. ```ts function resolveLocale(req) { return req.cookies?.locale || getRequestLocale(req); } app.use((req, res, next) => withGT(resolveLocale(req), () => next())); ``` `withGT` resolves the value you pass against your configured `locales`, so an unsupported locale falls back to the default. Read the active locale anywhere in a request with [`getLocale`](/docs/node/reference/functions/get-locale). ## Next steps - /docs/node/guides/translating-strings - /docs/node/guides/configuring - /docs/node/guides/storing-translations