# General Translation React SDKs (gt-react, gt-next, gt-react-native): getMessages
URL: https://generaltranslation.com/zh/docs/react/tanstack-start/reference/functions/get-messages.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 使用 General Translation 在 TanStack Start 运行时中解析已注册的消息。getMessages 的 API 参考。

`getMessages` 函数会返回一个解析器，用于解析通过 [`msg`](/docs/react/reference/functions/msg) 注册的字符串。从 `gt-tanstack-start` 导入该函数。

## 概览 [#overview]

```ts
import { getMessages, msg } from 'gt-tanstack-start';

const status = msg('Ready');
const m = await getMessages();
const translated = m(status);
```

```ts
getMessages(): Promise<MessageTranslationFunction>
```

## 工作原理 [#how-it-works]

在服务器端，`getMessages` 会读取由 [`gtMiddleware`](/docs/react/tanstack-start/reference/functions/gt-middleware) 创建的区域设置和国际化配置。在浏览器中，它会读取由 [`initializeGT`](/docs/react/reference/config#initialize) 初始化的条件存储。它会根据当前运行时，将编码后的消息解析为对应的翻译内容。

如果在未处于活动中的中间件请求上下文时进行服务器端调用，则会抛出异常。

## 返回值 [#returns]

**类型** `Promise<(encodedContent: string, options?: object) => string>`

解析后返回的函数会根据当前请求的区域设置翻译编码后的内容。传递给 [`msg`](/docs/react/reference/functions/msg) 的变量优先于传递给解析器的变量。

## 示例 [#example]

```ts
import { createServerFn } from '@tanstack/react-start';
import { getMessages, msg } from 'gt-tanstack-start';

const STATUS = {
  active: msg('Active'),
  paused: msg('Paused'),
};

export const loadStatus = createServerFn({ method: 'GET' }).handler(
  async () => {
    const m = await getMessages();
    return m(STATUS.active);
  }
);
```

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
