# @diglot/store 中文文档

规范地址：https://npmcn.com/package/%40diglot/store/

版本：0\.2\.2
npm 元数据更新时间：2026-11-08T11:45:52.910Z
中文译文更新时间：2026-11-12T09:29:17.963Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40diglot/store
原文对照：https://npmcn.com/package/%40diglot/store/?lang=original
项目主页：https://github.com/danielroe/diglot#readme
源码仓库：https://github.com/danielroe/diglot

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：74.6 kB，9 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.18\.0
- 运行依赖：3 个
- 首次发布：2026-11-02T18:45:59.151Z
- 最新版本发布：2026-11-08T11:45:52.456Z
- 近 30 天下载量：3663（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 10 个）

## 中文简介

用于 diglot 翻译的 git 记录存储

## 安装

```sh
npm install @diglot/store
```

也可以使用：`pnpm add @diglot/store`、`yarn add @diglot/store`、`bun add @diglot/store`

## README

# @ diglot/ 仓库

(原始内容存档于2018-09-21) (英语). Git record store of [挖掘机](https://npmcn.com/package/README.md): 翻译记录、源清单、语言包和装入 `diglot.config.ts` 财务报告和审定财务报表 `sources.yml`。 。 。 .

```bash
pnpm add @diglot/store @diglot/core
```

## 版式

```
diglot.config.ts
sources.yml                      repositories, refs and directories that feed the corpus
glossary.yml                     optional terminology shared by every locale (x18n shape)
<locale>/
  glossary.yml                   terminology for this locale
  style.yml                      style and typography rules
  locale.yml                     machine translation switch and review metrics
  segments/<hh>/<hash>.json      one record per locale and hash
.diglot/manifest/<source>.json   source segments per file, one entry per line
.diglot/policy.json              snapshot of the extraction policy
dist/<locale>.json               built bundle: { version, locale, records }
```

## 使用量

```ts
import { build, createManifest, liveHashes, loadConfig, loadLocale, readManifests, readSource, writeManifest, writeRecord } from '@diglot/store'

const config = await loadConfig('.')
const snapshot = await readSource(config.sources[0], config.root)

await writeRecord(config.root, 'fr', record)
const records = await loadLocale(config.root, 'fr')

await build(config.root, { locales: config.locales, only: liveHashes(await readManifests(config.stateDir)) })
```

-   记录以固定的密钥顺序和后继的新行进行序列化,并在读取和书写时验证.
-   `readSource` 读取来源 `ref` 或来自工作树,当没有 `ref` 已经设定. `include` 财务报告和审定财务报表 `exclude` 阴道相对 `dir` 默认标记文件并 `.navigation.yml`。 。 。 .
-   `writePolicy(stateDir, policy)` 写入 `.diglot/policy.json`, (中文(简体) ), `@diglot/core`是因为 `snapshotPolicy` 组合策略,以及 `readPolicy(stateDir)` 读它. `diglot extract` 行动者将它写在《古兰经》的旁边,并将每个《古兰经》写出 `policy` 给保险单的指纹.
-   `build` 返回,每个区域,捆绑 `path`,数字 `records` 在其中,有许多是审查者 `rejected`,以及有多少人 `skipped` 因为他们的大麻不是活的.
-   `parseBundle` 读取已建 `dist/<locale>.json` 改为 a `Map<hash, record>`. Bundles 包括被拒绝的记录,因此消费者可以显示自己的状态.
-   `loadGlossary(root, locale, { shared })` 阅读共享词汇表(`config.glossary`和 `<locale>/glossary.yml`; 地语条目用同名词来替换共享条目. 两个文件都接受diglot的形状(`terms` 带有 `decision` 每个条目)和 [x18n 时](https://github.com/x18n-dev/x18n)是因为 `glossary` 形状,因此一个文件可以服务两个工具。 见 [`@diglot/mt`](https://npmcn.com/package/%40diglot/mt#glossary) 用于绘图.
-   `loadStyle(root, locale)` 读取 `<locale>/style.yml`数字 : `rules`, (中文(简体) ), `typography` 财务报告和审定财务报表 `lengthRatio`。 。 。 .
-   `loadLocaleState(root, locale)` 读取 `<locale>/locale.yml`数字 : `mt.enabled`,以及 `governance` 指标(`activeReviewers`, (中文(简体) ), `approvalRate`, (中文(简体) ), `reviewLatencyDays`, (中文(简体) ), `updatedAt`用于维持治理工作. `mtEnabled(state)` 是动作读取的开关.
-   `parseGlossary(data, locale, file)`, (中文(简体) ), `mergeGlossary(shared, own)`, (中文(简体) ), `parseLocaleState(data, file)` 财务报告和审定财务报表 `parseStyle(data, file)` 是这些装载器后面的解析器, 用于从任何地方解析 YAML 。 它们也从 `@diglot/store/runtime`。 。 。 .

## 运行时间

`@diglot/store/runtime` 读取一个没有检查或文件系统的商店,用于为翻译库最新承诺的翻译服务的服务器。 它没有节点内置进口.

```ts
import { readArchive } from '@diglot/store/runtime'

const response = await fetch(`https://codeload.github.com/nuxt/translations/tar.gz/${sha}`)
const archive = await readArchive(response.body!, { locales: ['fr'] })

const fr = archive.records.get('fr') // Map<hash, unknown>: read each with `parseRecord`
```

提取并按保单在运行时适用

```ts
import { restorePolicy } from '@diglot/core'

if (!archive.policy)
  throw new Error('the archive has no .diglot/policy.json')
const policy = restorePolicy(archive.policy) // throws when the policy has a custom `salt` or `codeLabel` that is not passed in
await apply(doc, translations, { policy })
```

-   `readArchive(input, { locales, manifests })` 读取 `tar` 或者说 `tar.gz` 归档( 流, `Uint8Array` 或者说 `ArrayBuffer`当它到达,只保存记录, 清单在 `.diglot/manifest`,政策简介 `.diglot/policy.json` (截至 `policy`)和根和每个地块目录中的YAML文件. 撤销顶级目录 `sha` 来源于 Pax 头条 GitHub 写道. 无效的JSON记录和清单 `hash` 不匹配文件名,并跳过其它版本的列表并列出于 `invalid`。当归档被截断或流出错误时,它会拒绝.
-   `manifestCoverage(manifest, records, { visible })` 返回列表中每个文件的单词 `recordStatus`,以及 `fileCoverage(entries, records, { visible })` 一个文件. `records` 是一个由散列组成的映射或取景函数。 每一记录都按其明显的条目加以验证,因此,无法验证的文本算作: `rejected`; 记录 `visible` 返回时 `false` 计数为 `untranslated`。没有文字的部分被忽略。 明显帮助者(`createManifest`, (中文(简体) ), `serialiseManifest`, (中文(简体) ), `validationTarget`, (中文(简体) ), `liveHashes`)也在此导出.
-   `changedRecords(before, after, fields)` 返回在两套记录之间添加、删除或更改记录的散列(图,或带有 `get` 财务报告和审定财务报表 `keys`比较 `text`, (中文(简体) ), `review`, (中文(简体) ), `origin` 财务报告和审定财务报表 `derived` 除非 `fields` 说不然。 用它来查找页面的推移已更改 .
-   `parseRecordFile(text, hash)` 解析记录文件的文本,返回 `undefined` 当没有记录的时候,它不是真实的,也不是真实的 `hash` 不一样. `parseRecordPath(path)` 反向为 `recordPath`数字 : `{ locale, hash }` 页:1 `<locale>/segments/<hh>/<hash>.json`, (中文(简体) ), `undefined` 对于任何其他路径。 两者, `recordPath` 财务报告和审定财务报表 `serialiseRecord` 也从主条目导出.
-   `archiveGlossary(archive, locale, { shared })`, (中文(简体) ), `archiveLocaleState(archive, locale)` 财务报告和审定财务报表 `archiveStyle(archive, locale)` 读一个地方的合并词汇表, `locale.yml` 财务报告和审定财务报表 `style.yml` 从 `archive.files`,上面装填器从磁盘上读取. `shared` 默认为 `glossary.yml`; 通过 `false` 没有。 他们把文件放错了.
-   `encodeRecords(records, { compression })` 序列化一个地方记录(a) `Map` 或被散列键入一个字符串,用于密钥值缓存:被装入列中,重复被封存,然后被压缩并被编码. `compression` 实值 `gzip` (默认的,可以随时阅读), `zstd` (写作速度快3倍,读作速度快2倍) `node:zlib` 拥有zstd)或 `none`失败的值 `parseRecord` 或者坐在另一道散列之下. `decodeRecords(data)` 读回一个 `Map<hash, record>`。 。 。 .
-   `decodeRecordsView(data)` 将相同的字符串读入 `ReadonlyMap<hash, record>` 用于解码每个寒冷起步的地盘记录但只读取其中一部分的服务器。 包的结构在前面检查;读取一个不正确的记录抛出. 迭接取景能造出一切记录.
-   何处 `process.getBuiltinModule` 已存在(节点、 Deno、 Bun),均使用 `node:zlib`; 其它处 `CompressionStream` 财务报告和审定财务报表 `DecompressionStream`。 。 。 .

## 常见问题

### @diglot/store 是什么？

用于 diglot 翻译的 git 记录存储

### 如何安装 @diglot/store？

在项目目录运行 npm install @diglot/store，或使用 pnpm add / yarn add / bun add。

### @diglot/store 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @diglot/store 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @diglot/store 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22\.18\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @diglot/store 可以商用吗？

@diglot/store 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @diglot/store 的下载量有多少？

根据 npm 官方下载统计，@diglot/store 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,663 次，日均约 122 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @diglot/store 还在维护吗？

最新版本 0\.2\.2 发布于 2026/11/08（3 天前）；至今共发布 10 个版本，其中过去 12 个月发布了 10 个；首次发布于 2026/11/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

