# gt-next: General Translation Next.js SDK: getMessages
URL: https://generaltranslation.com/en-GB/docs/next/api/strings/get-messages.mdx
---
title: getMessages
description: API reference for the getMessages() string translation function
---
## Overview
The `getMessages` function is an async function for translating encoded strings from `msg` at build time.
```jsx
const m = await getMessages();
{ m(encodedString) }
;
```
**Buildtime Translation:**
`getMessages` translations occur at build time, before your app is deployed.
You can pass encoded strings from `msg` and they will be translated to the user's preferred language.
## Reference
### Parameters
None
### Returns
A promise resolving to a callback function, `m`, which translates the provided encoded content from `msg`.
```jsx
Promise<(encodedContent: string, options?: Record) => string>
```
| Name | Type | Description |
| ---------------- | --------------------- | ------------------------------------------------------------ |
| `encodedContent` | `string` | The encoded string content from `msg` to be translated. |
| `options?` | `Record` | Optional parameters to pass variables to the encoded string. |
***
## Behaviour
### Production
During the CD process, any content inside a `msg` 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 fall back to the original content.
Make sure to follow the [deployment guide here](/docs/next/tutorials/quickdeploy).
### Development
During development, the `m` 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 behaviour.
You will see a delay during on-demand translation in development.
This will not occur in production builds unless content is explicitly translated on demand,
i.e. using [`tx`](/docs/next/api/strings/tx) or [``](/docs/next/api/components/tx).
***
## Example
### Basic usage
You can use `getMessages` to translate encoded strings from `msg`.
```javascript copy
import { msg, getMessages } from 'gt-next/server';
const encodedGreeting = msg('Hello, Alice!');
export default async function TranslateGreeting() {
const m = await getMessages();
return (
{m(encodedGreeting)}
);
}
```
Note: "Alice" will be translated to the user's preferred language.
### Using variables [#variables]
You can pass variables to encoded strings.
```javascript copy
import { msg, getMessages } from 'gt-next/server';
const encodedGreeting = msg('Hello, {name}!');
export default async function TranslateGreeting() {
const m = await getMessages();
return (
{m(encodedGreeting, { name: 'Bob' })} {/* This will display "Hello, Bob!" */}
);
}
```
### `msg` variables override `m` variables
When you pass variables to both `msg` and `m`, the variables passed to `msg` override those passed to `m`.
```javascript copy
import { msg, getMessages } from 'gt-next/server';
const encodedGreeting = msg('Hello, {name}!', { name: 'Alice' });
export default async function TranslateGreeting() {
const m = await getMessages();
return (
{m(encodedGreeting, { name: 'Bob' })}
);
}
```
Note: This will display "Hello, Alice!" - the variable is not overridden at render time.
### Using ICU message format
`gt-next` supports ICU message format, which also lets you format your variables.
```javascript copy
import { msg, getMessages } from 'gt-next/server';
const encodedMessage = msg('There are {count, plural, =0 {no items} =1 {one item} other {{count} items}} in the cart', { count: 10 });
export default async function TranslateGreeting() {
const m = await getMessages();
return (
{m(encodedMessage)}
);
}
```
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/).
***
## Notes
* The `getMessages` function is a server-side function that translates the encoded strings from `msg`.
* Translating strings with `getMessages` happens before runtime, during the build process (unless in development).
## Next steps
* See [`useMessages`](/docs/next/api/strings/use-messages) for client-side translation of strings encoded at build time.
* See [`msg`](/docs/next/api/strings/msg) for encoding strings for translation.
* For runtime translations, see [`tx`](/docs/next/api/strings/tx) and [``](/docs/next/api/components/tx).