# node: getGT URL: https://generaltranslation.com/en-US/docs/node/api/get-gt.mdx --- title: getGT description: API reference for the getGT string translation function --- ## Overview The `getGT` function is an async function that returns a translation function for translating strings. It resolves translations registered at build time by the GT compiler. ```js import { getGT } from 'gt-node'; const gt = await getGT(); const greeting = gt('Hello, world!'); ``` **Request Context Required:** `getGT` must be called within a [`withGT`](/docs/node/api/with-gt) callback so it knows which locale to use. ## Reference ### Parameters None. ### Returns A promise that resolves to a translation function `gt`: ```ts Promise<(content: string, options?: InlineTranslationOptions) => string> ``` | Name | Type | Description | | ---- | ---- | ----------- | | `content` | `string` | The string to translate. | | `options?` | `InlineTranslationOptions` | Optional translation options (variables, context, etc.). | The `gt` function returns the translated string, or the original string if no translation is found. #### `InlineTranslationOptions` | Prop | Type | Description | | ---- | ---- | ----------- | | `$context?` | `string` | Additional context to help disambiguate translations. | | `$id?` | `string` | A custom ID for the translation entry. | | `$maxChars?` | `number` | Maximum character count for the translation. | | Other keys | `any` | Variable values to interpolate into the string using `{key}` syntax. | --- ## Examples ### Simple translation ```js title="handler.js" import { withGT, getGT } from 'gt-node'; function handleRequest(locale: string) { return withGT(locale, async () => { const gt = await getGT(); return gt('Hello, world!'); }); } ``` ### With variables Use `{variableName}` syntax in the string and pass values in the options object: ```js title="handler.js" import { withGT, getGT } from 'gt-node'; function handleGreeting(locale: string, name: string) { return withGT(locale, async () => { const gt = await getGT(); return gt('Hello, {name}!', { name }); }); } ``` ### With ICU message format `gt-node` supports ICU message format for advanced formatting: ```js title="handler.js" const gt = await getGT(); const balance = gt( 'Your balance: {amount, number, ::currency/USD}', { amount: 1234.56 } ); ``` --- ## Notes - `getGT` returns a **build-time** translation function. Strings are translated during the CD process before deployment. - In development, translations happen on demand (requires a Dev API key). - If no translation is found, the original string is returned as a fallback. ## Next steps - See [`getMessages`](/docs/node/api/get-messages) for resolving pre-registered messages. - See [`withGT`](/docs/node/api/with-gt) for setting up the locale context.