# General Translation Platform: GTRuntime
URL: https://generaltranslation.com/zh/docs/platform/core/reference/runtime.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 无需项目管理即可使用运行时翻译、格式化和区域设置辅助函数。GTRuntime 的 API 参考。

如果你的应用不需要文件或项目管理，请从 `generaltranslation/runtime` 导入 `GTRuntime`。受支持的 [`GT`](/docs/platform/core/reference/gt-class/constructor) 类继承自 `GTRuntime`，并在其基础上添加了这些管理方法。

| 导出                                      | 描述                |
| --------------------------------------- | ----------------- |
| [`GTRuntime`](#runtime)                 | 运行时翻译、格式化和区域设置方法。 |
| [`GTConstructorParams`](#configuration) | 通用的构造函数与重新配置选项。   |

## `GTRuntime` [#runtime]

**类型** class · **构造函数** `new GTRuntime(params?: GTConstructorParams)`

运行时入口不包含文件/项目管理客户端，但保留了 [`translate`](/docs/platform/core/reference/gt-class-methods/translation/translate)、[`translateMany`](/docs/platform/core/reference/gt-class-methods/translation/translate-many)、格式化功能、区域设置辅助函数以及 [`setConfig`](/docs/platform/core/reference/gt-class/set-config)。这些方法的运行时契约与继承自 [`GT`](/docs/platform/core/reference/gt-class/constructor) 的对应方法一致。

```ts title="format.ts"
import { GTRuntime } from 'generaltranslation/runtime';

const runtime = new GTRuntime({ sourceLocale: 'en', targetLocale: 'en-US' });
console.log(runtime.formatNum(1234.5)); // 1,234.5
```

格式化和区域设置辅助函数无需任何 API 凭据。运行时翻译则需要项目 ID 和 API Key。

请勿将 API Key 嵌入到部署至浏览器或移动端的 bundle 中。

## `GTConstructorParams` [#configuration]

**类型** object · **可选** · **默认值** `{}`

从 `generaltranslation/runtime` 导入该类型。它与根类使用的[构造函数配置](/docs/platform/core/reference/types/gt-constructor-params)相同，包括 API Key、项目 ID、基础 URL、区域设置和自定义映射，但不接受 `fetch`、`timeoutMs`、`retryPolicy` 或 `apiVersion`。

如需重新配置实例，请使用 [`setConfig`](/docs/platform/core/reference/gt-class/set-config)。

## Sitemap

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