# 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 --- title: getMessages description: 使用 General Translation 在 TanStack Start 服务器函数中解析已注册的消息。getMessages 的 API 参考。 --- `getMessages` 函数会返回一个解析器,用于解析通过 [`msg`](/docs/react/reference/functions/msg) 注册的字符串。从 `gt-tanstack-start/server` 导入该函数。 ## 概览 [#overview] ```ts import { msg } from 'gt-tanstack-start'; import { getMessages } from 'gt-tanstack-start/server'; const status = msg('Ready'); const m = await getMessages(); const translated = m(status); ``` ```ts getMessages(): Promise ``` ## 工作原理 [#how-it-works] `getMessages` 会读取由 [`gtMiddleware`](/docs/react/tanstack-start/reference/functions/gt-middleware) 创建的区域设置和国际化配置。它会根据当前请求,将编码后的消息解析为对应的翻译内容。 如果在未处于活动中的中间件请求上下文时调用此函数,则会抛出异常。 ## 返回值 [#returns] **类型** `Promise<(encodedContent: string, options?: object) => string>` 解析后返回的函数会根据当前请求的区域设置翻译编码后的内容。传递给 `msg` 的变量优先于传递给解析器的变量。 ## 示例 [#example] ```ts import { createServerFn } from '@tanstack/react-start'; import { msg } from 'gt-tanstack-start'; import { getMessages } from 'gt-tanstack-start/server'; const STATUS = { active: msg('Active'), paused: msg('Paused'), }; export const loadStatus = createServerFn({ method: 'GET' }).handler( async () => { const m = await getMessages(); return m(STATUS.active); } ); ```