# Vue: GTFunction
URL: https://generaltranslation.com/zh/docs/vue/reference/types/gt-function.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 说明用于 Vue 纯字符串目录查找的同步回调。GTFunction 的 API 参考。

[`useGT()`](/docs/vue/reference/composables/use-gt) 返回的回调与模块级导出的 [`t()`](/docs/vue/reference/functions/t) 具有相同的签名。二者的状态归属和可用性不同，但查找结果相同。

## 概览 [#overview]

```ts
type GTFunction = (
  message: string,
  options?: GTStringOptions
) => string;
```

| 参数                    | 描述                      | 类型                                                               | 可选 | 默认值  |
| --------------------- | ----------------------- | ---------------------------------------------------------------- | -- | ---- |
| [`message`](#message) | 要翻译的源字符串。               | `string`                                                         | 否  | —    |
| [`options`](#options) | 用于计算 目录 哈希值的可选上下文。 | [`GTStringOptions`](/docs/vue/reference/types/gt-string-options) | 是  | `{}` |

## 参数 [#parameters]

### `message`

**类型** `string` · **必填**

用于计算普通 `STRING` 哈希的原始文本。大括号仍属于该文本的一部分，并非插值占位符。

### `options`

**类型** [`GTStringOptions`](/docs/vue/reference/types/gt-string-options) · **可选** · **默认值** `{}`

仅支持 `$context`，用于区分相同的源字符串。

## 返回值 [#returns]

**类型** `string`

返回活动 目录 中与计算出的 哈希 对应的字符串值。如果 entry 不存在，或 目录 值不是字符串，则原样返回 `message`。

查找 为同步操作，不会执行网络请求、ICU 处理或 插值。

## 实现 [#implementations]

| API                                                 | 状态来源                                                                                  | 区域设置更新                                         |
| --------------------------------------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------- |
| [`useGT()`](/docs/vue/reference/composables/use-gt) | 安装在当前 Vue 应用中的 [`GTPlugin`](/docs/vue/reference/types/gt-plugin)。                     | 在模板、计算属性或响应式副作用中调用该回调；响应式插件更改区域设置或加载目录后，会重新运行。 |
| [`t()`](/docs/vue/reference/functions/t)            | 由 [`initializeGTSPA()`](/docs/vue/reference/functions/initialize-gt-spa) 创建的浏览器全局运行时。 | 只有当 SPA 的区域设置设置器重新加载页面并再次执行模块时，模块级结果才会更新。      |

未安装插件时调用 [`useGT()`](/docs/vue/reference/composables/use-gt)，组合式函数尝试访问状态时会抛出异常。在服务器端调用 [`t()`](/docs/vue/reference/functions/t)，或在 SPA 初始化完成前调用，也会抛出异常。

## 示例 [#example]

```ts
import type { GTFunction } from 'gt-vue';

function translateNavigation(gt: GTFunction) {
  return {
    home: gt('Home'),
    settings: gt('Settings'),
  };
}
```

## Sitemap

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