# gt-node: General Translation Node.js SDK: getGT URL: https://generaltranslation.com/en-GB/docs/node/reference/functions/get-gt.mdx --- title: getGT description: Get a General Translation function for the current request locale to translate inline strings. API reference for getGT. --- An async function that returns a translation function for the current request's locale. It resolves translations registered at build time by the General Translation compiler, falling back to the source string if no translation is found. ## Overview [#overview] Await `getGT` inside a [`withGT`](/docs/node/reference/functions/with-gt) scope to get a synchronous `gt(message, options?)` function, then translate strings with it. ```ts import { getGT } from 'gt-node'; const gt = await getGT(); const greeting = gt('Hello, world!'); ``` Signature: ```ts getGT(): Promise type GTFunctionType = (message: string, options?: GTTranslationOptions) => string; ``` *Note: `getGT` must be called within a [`withGT`](/docs/node/reference/functions/with-gt) callback so it knows which locale to use. It also accepts an internal `_messages` argument used by the compiler for development hot reload; you do not pass it directly.* ## How it works [#how-it-works] * **Build-time translations.** `getGT` returns a build-time translation function. Strings are translated during the CD process before deployment, so production requests serve cached translations without a network round trip. * **Development.** In development, translations happen on demand and require a Dev API key. * **Fallback.** If no translation is found, the original (interpolated) source string is returned. * **Interpolation.** Use `{variableName}` placeholders in the string and pass values in the options object. `gt-node` supports [ICU message format](https://unicode-org.github.io/icu/userguide/format_parse/messages/) for advanced formatting. ## Parameters [#parameters] `getGT` takes no parameters. The returned `gt` function takes: | Parameter | Description | Type | Optional | Default | | --------------------- | ------------------------------------------------ | ---------------------- | -------- | ------- | | [`message`](#message) | The string to translate. | `string` | No | — | | [`options`](#options) | Interpolation variables and translation options. | `GTTranslationOptions` | Yes | `{}` | ### `message` [#message] **Type** `string` · **Required** The string to translate. It may contain `{variable}` placeholders for ICU interpolation. ### `options` [#options] **Type** `GTTranslationOptions` · **Optional** Translation options and interpolation variables: * `$context?: string` — additional context to help disambiguate translations. * `$id?: string` — a custom ID for the translation entry. * `$locale?: string` — override the locale for this request. * `$format?: string` — the message format. Defaults to `'ICU'`. * `$maxChars?: number` — maximum character count for the translation. * `$requiresReview?: boolean` — whether the translation requires approval before use. * Any other keys are treated as values to interpolate into the string using `{key}` syntax. ## Returns [#returns] **Type** `Promise` Resolves to the `gt` translation function. Calling `gt(message, options?)` returns the translated string, or the original (interpolated) string if no translation is found. ## Examples [#examples] ```ts title="handler.js" // Simple translation import { withGT, getGT } from 'gt-node'; function handleRequest(locale) { return withGT(locale, async () => { const gt = await getGT(); return gt('Hello, world!'); }); } ``` ```ts title="handler.js" // With variables — use {name} in the string and pass values in the options object import { withGT, getGT } from 'gt-node'; function handleGreeting(locale, name) { return withGT(locale, async () => { const gt = await getGT(); return gt('Hello, {name}!', { name }); }); } ``` ```ts title="handler.js" // With ICU message format const gt = await getGT(); const balance = gt( 'Your balance: {amount, number, ::currency/USD}', { amount: 1234.56 } ); ``` ## Notes [#notes] * `getGT` returns a build-time translation function; strings are translated during the CD process before deployment. * In development, translations happen on demand and require a Dev API key. * If no translation is found, the original string is returned as a fallback. * For strings only known at runtime, use [`tx`](/docs/node/reference/functions/tx); for strings registered at module scope, use [`msg`](/docs/node/reference/functions/msg) with [`getMessages`](/docs/node/reference/functions/get-messages).