# vue: TranslationCatalog URL: https://generaltranslation.com/zh/docs/vue/reference/types/translation-catalog.mdx --- title: TranslationCatalog description: 表示单个区域设置中所有普通字符串和富内容翻译。TranslationCatalog 的 API 参考。 --- CLI 会生成这个以哈希值为键的对象,插件可通过 [`LoadTranslations`](/docs/vue/reference/types/load-translations) 回调获取该对象。应用代码通常通过翻译组件和组合式函数读取目录,而非直接检查目录。 ## 概览 [#overview] ```ts import type { JsxChildren } from 'generaltranslation/types'; type TranslationCatalog = Record; ``` | 成员 | 描述 | 类型 | | ----------------- | ------------------------ | ----------------------------------------------------------------- | | [`hash`](#hash) | 根据源内容和翻译元数据生成的稳定目录键。 | `string` | | [`value`](#value) | 纯 `STRING` 翻译或序列化的富内容翻译。 | [`JsxChildren`](/docs/platform/core/reference/types/jsx-children) | ## 成员 [#members] ### `hash` **类型** `string` · **必填** 每个属性键对应一个提取出的源条目。普通字符串的 identity 包含源字符串和可选的 `$context`。富内容还包含其结构化源内容和 [``](/docs/vue/reference/components/t) 元数据。 将哈希视为不透明值。请让 `gt` CLI 生成和更新它们;更改源内容或影响哈希的元数据会生成不同的键。 ### `value` **类型** [`JsxChildren`](/docs/platform/core/reference/types/jsx-children) · **必填** 普通字符串 `STRING` 条目存储译文字符串。富内容 [``](/docs/vue/reference/components/t) 条目存储供 Vue 渲染器使用的序列化内容树。 公共传输类型包含生成的目录所使用的完整标量形式: ```ts type JsxChildren = boolean | null | JsxChild | JsxChild[]; type JsxChild = string | JsxElement | Variable; ``` 布尔值和 `null` 可作为标量富内容值出现,包括嵌套元素和分支中的内容。手动编写的子数组使用范围更窄的 `JsxChild[]` 结构。请勿手动编写序列化的元素或变量记录;其索引和元数据必须与提取出的源树一致。 ## 查找行为 [#lookup-behavior] [`useGT()`](/docs/vue/reference/composables/use-gt)、[`t()`](/docs/vue/reference/functions/t) 和 [`useMessages()`](/docs/vue/reference/composables/use-messages) 在普通字符串查找中仅接受字符串目录值。键缺失或值不是字符串时,将回退到源字符串。 [``](/docs/vue/reference/components/t) 可使用富内容值;如果没有匹配的翻译,则回退到其源插槽。默认区域设置无需目录,因为其源内容即为后备内容。 ## 示例 [#example] 以目录形式返回生成的 JSON 对象: ```ts title="src/loadTranslations.ts" import type { LoadTranslations, TranslationCatalog } from 'gt-vue'; const loadTranslations: LoadTranslations = async (locale) => { const module = await import(`./_gt/${locale}.json`); return module.default as TranslationCatalog; }; export default loadTranslations; ``` 当某个区域设置没有目录且应渲染源内容时,返回 `{}`。