# The translate function

Sometimes you need to translate content in your React application that's not part of your JSX templates. One example is the metadata of a Next.js application.&#x20;

Luckily this is no problem with Magic Translate and can easily be achieved with the translate function that is set up when preparing Magic Translate for SSR.&#x20;

As documented on the [React SSR](/magic-translate/clients/react-ssr.md) page, to get started you needed to set up the translate function and the `<T>` component, like so:

```typescript
import { createT, setupTranslate } from "@magic-translate/react-ssr";

const magicTranslateConfig = {
  apiKey: "<your-api-key>",
}

// the translate function!
export const translate = setupTranslate(magicTranslateConfig);

export const T = createT(translate);
```

The `translate` function set up here is just a plain function that takes a language, a text and optional options as input parameters and returns the translation of the string asynchronously.

```typescript
const translation = await translate(
    Language.ZH,
    'This sentence will be translated to Chinese'
)
```

Going back to the example of Next.js metadata, here's how you could translate your metadata with the `translate` function:

```typescript
import { Metadata, NextPage } from 'next';
import { Language } from '@magic-translate/react-ssr'

export async function generateMetadata(
  { params }: { params: { lang : Language } }): Promise<Metadata> {
  return {
    title: await translate(
      params.lang,
      'This page title will be translated'
    ),
  };
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.magictranslate.io/magic-translate/clients/react-ssr/the-translate-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
