@ diglot/ 仓库
(原始内容存档于2018-09-21) (英语). Git record store of 挖掘机: 翻译记录、源清单、语言包和装入 diglot.config.ts 财务报告和审定财务报表 sources.yml。 。 。 .
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 }
使用量
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改为 aMap<hash, record>. Bundles 包括被拒绝的记录,因此消费者可以显示自己的状态.loadGlossary(root, locale, { shared })阅读共享词汇表(config.glossary和<locale>/glossary.yml; 地语条目用同名词来替换共享条目. 两个文件都接受diglot的形状(terms带有decision每个条目)和 x18n 时是因为glossary形状,因此一个文件可以服务两个工具。 见@diglot/mt用于绘图.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 读取一个没有检查或文件系统的商店,用于为翻译库最新承诺的翻译服务的服务器。 它没有节点内置进口.
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`
提取并按保单在运行时适用
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。 。 。 .