# General Translation Changelog: gt-next 6.13.0: msg() 支持数组
URL: https://generaltranslation.com/zh/blog/gt-next_v6_13_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2026-02-25

## 概览

[`msg()`](/docs/react/reference/functions/msg) 现在支持接受数组。

此前，如果要注册一组相关字符串，需要将每一项分别包装：

```tsx
const confirmations = [
  msg("Yes"),
  msg("Yup"),
  msg("Right"),
  msg("Absolutely"),
  msg("Exactly"),
];
```

这有两个问题。首先，每一行都需要调用一次 [`msg()`](/docs/react/reference/functions/msg)。其次，相关字符串通常需要相同的元数据——`$context`、`$id` 等——而且由于 CLI 会在构建时解析这些元数据，所以必须把它们直接内联进去。对于像 &quot;Right&quot; 或 &quot;Exactly&quot; 这种脱离上下文就有歧义的字符串，最终你不得不在每个条目里重复写上 `$context`：

```tsx
const confirmations = [
  msg("Yes"),
  msg("Yup"),
  msg("Right", { $context: "As in a confirmation" }),
  msg("Absolutely", { $context: "As in a confirmation" }),
  msg("Exactly", { $context: "As in a confirmation" }),
];
```

现在你可以这样做了：

```tsx
const confirmations = msg([
  "Yes",
  "Yup",
  "Right",
  "Absolutely",
  "Exactly",
], { $context: "Confirmation responses" });
```

## 设计

### ID 生成

指定 `$id` 后，数组中的每一项都会获得一个基于索引的 id：`${id}.0`、`${id}.1` 等。

```tsx
const greetings = msg([
  "Hi",
  "Hello",
  "Howdy",
], { $id: "greeting" });
// "Hi"    → id: "greeting.0"
// "Hello" → id: "greeting.1"
// "Howdy" → id: "greeting.2"
```


## 为什么不用对象？

我们也曾想把这一点扩展到对象，但最终没有这么做。对象通常会同时包含可翻译和不可翻译的字段：

```tsx
{
  id: 'planning.v1',           // 不翻译
  message: 'Not yet enabled',  // 翻译
}
```

如果不引入更多语法，就没有简洁明了的方式来指定哪些字段需要注册。数组则没有这个问题——每个元素都是待翻译的字符串。


## 未来

为 `gt()` 提供数组支持是很自然的下一步。`gt()` 和 [`msg()`](/docs/react/reference/functions/msg) 都是注册函数，因此让两者保持一致很合理。这一点也适用于 `m()`，因为 [`msg()`](/docs/react/reference/functions/msg) 和 `m()` 经常配合使用——让 `m()` 接受数组，可以确保把 [`msg()`](/docs/react/reference/functions/msg) 的输出传给 `m()` 时不会出错。

## Sitemap

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