# gt-next: General Translation Next.js SDK: useGT URL: https://generaltranslation.com/en-US/docs/next/api/strings/use-gt.mdx --- title: useGT description: API reference for the useGT string translation function --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Overview The `useGT` function is a hook for translating strings at build time. ```jsx const gt = useGT();

{gt('This text will be translated')}

; ``` **Buildtime Translation:** `useGT` translations occur at buildtime, before your app deploys. Though you can pass variables to the translated string, you can only translate content known at build time. ## Reference ### Parameters None ### Returns A callback function, `gt`, which translates the provided content. ```jsx (content: string, options?: InlineTranslationOptions) => string ``` | Name | Type | Description | | ---------- | -------------------------------------------------------------------------------- | ----------------------------------------------------- | | `content` | `string` | The string content to be translated. | | `options?` | [`InlineTranslationOptions`](/docs/next/api/types/inline-translation-options) | Translation options to customize the behavior of `gt`. | --- ## Behavior ### Production During the CD process, any content inside of a `gt` function will be translated before your application is deployed. This ensures fast load times for all locales, but it can only translate content known at build time. Once generated, translations are either (1) stored in the CDN or (2) stored in your app's build output, according to your configuration. From there, the translated content is served to your users. If a translation is not found, it will fallback to the original content. Make sure to follow the [deployment guide here](/docs/next/tutorials/quickdeploy). ### Development During development, the `gt` function will translate content on demand. This is useful for prototyping what your app will look like in different languages. Remember to add a Dev API key to your environment to enable this behavior. You will see a delay during on demand translation in development. This will not occur in production builds unless content is explicitly being translated on demand. --- ## Example ### Basic usage You can use `useGT` to translate strings. ```jsx copy import { useGT } from 'gt-next'; export default function TranslateGreeting() { const gt = useGT(); return

{gt('Hello, Alice!')}

; } ``` Note: "Alice" will be translated to the user's preferred language. ### Using variables [#variables] You can pass variables to dictionary translations. ```jsx copy import { useGT } from 'gt-next'; export default function TranslateGreeting() { const gt = useGT(); return

{gt('Hello, {name}!', { name: 'Alice' })}

; } ``` Note: "Alice" will not be translated to the user's preferred language because it is a variable. ### Using ICU message format `gt-next` supports ICU message format, which allows you to also format your variables. ```jsx copy import { useGT } from 'gt-next'; export default function TranslateGreeting() { const gt = useGT(); return (

{gt( 'There are {count, plural, =0 {no items} =1 {one item} other {{count} items}} in the cart', { count: 10 } )}

); } ``` ICU message format is a powerful way to format your variables. For more information, see the [ICU message format documentation](https://unicode-org.github.io/icu/userguide/format_parse/messages/). ### Importing from `gt-next` If operating under the `"use client"` directive, you should import from `gt-next` instead of `gt-next`. ```jsx copy 'use client'; import { useGT } from 'gt-next'; export default function TranslateGreeting() { const gt = useGT(); return

{gt('Hello, Alice!')}

; } ``` --- ## Notes - The `useGT` function is a hook that translates strings. - Translations strings with `useGT` happen before runtime, during the build process (unless in development).