# @diplodoc/translation 中文文档

规范地址：https://npmcn.com/package/%40diplodoc/translation/

版本：1\.10\.3
npm 元数据更新时间：2026-11-09T10:10:29.324Z
中文译文更新时间：2026-11-12T10:47:52.276Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40diplodoc/translation
原文对照：https://npmcn.com/package/%40diplodoc/translation/?lang=original
项目主页：https://github.com/diplodoc-platform/translation
源码仓库：https://github.com/diplodoc-platform/translation

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

- 包体积（解压后）：825 kB，154 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=24
- 运行依赖：24 个
- peer 依赖：markdown-it ^13\.0\.2
- 首次发布：2024-02-21T15:25:22.587Z
- 最新版本发布：2026-11-09T10:10:28.962Z
- 近 30 天下载量：9479（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：63（近 12 个月 20 个）

## 中文简介

减额翻译设施

## 安装

```sh
npm install @diplodoc/translation
```

也可以使用：`pnpm add @diplodoc/translation`、`yarn add @diplodoc/translation`、`bun add @diplodoc/translation`

## README

[![NPM version](https://img.shields.io/npm/v/@diplodoc/translation.svg?style=flat)](https://www.npmjs.org/package/@diplodoc/translation) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_translation&metric=alert_status)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_translation) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_translation&metric=coverage)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_translation) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_translation&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_translation) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_translation&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_translation) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_translation&metric=security_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_translation)

# @ diplodoc/ 翻译

## 区域

-   [导 言](https://npmcn.com/package/%40diplodoc/translation/#readme--introduction)
    
-   [项目概况](https://npmcn.com/package/%40diplodoc/translation/#readme--project-overview)
    
-   [目的和范围](https://npmcn.com/package/%40diplodoc/translation/#readme--purpose-and-scope)
    
-   [开始](https://npmcn.com/package/%40diplodoc/translation/#readme--getting-started)
    
-   [\* 安装](https://npmcn.com/package/%40diplodoc/translation/#readme--installation)
    
-   [• API](https://npmcn.com/package/%40diplodoc/translation/#readme--api)
    
-   [使用量](https://npmcn.com/package/%40diplodoc/translation/#readme--usage)
    

## 导 言

嘿,这里

你厌倦了复制并粘贴你的减记内容到翻译工具,看到减记语法而不是可转换文本和相撞吗?

别再说了

与 `@diplodoc/translation`,您可以为 CAT 工具生成骨架/ XLIFF 并作曲向后翻译 Markdown .

## 项目概况

这个库覆盖了两个API接口:取出并作曲

从 markdown 文件 QQ 中提取文本并生成一个骨架/ XLF 文件 。 🧑‍💻

用 XLF 文件的翻译来编译摘录的文本来创建已翻译的标记下文件. 🌎📄💬

说再见手动翻译工作 并精简工作流程 `@diplodoc/translation`。 。 。 .

## 目的和范围

抓住你的帽子,伙计们! 这个图书馆正在解决一些严重的 减记翻译问题!

🚫告别由天真的方法导致的翻译不必要的沉重负担,这些方法包括将减分语法构造入文本段.

不要让我们开始 "collisions" -yikes! 但不要担心,这个库已经得到了你的支持 一个可靠的解决方案 从标记下提取文本内容 没有那些pesky相撞.

怎么会? 当然,通过剖析和渲染xlf和骨架 所以,坐下,放松, 让这个图书馆 处理所有你的减分翻译需要.

说再见吧,那些讨厌的话题 和你好,高效和准确的翻译与 `@diplodoc/translation`。 。 。 .

## 开始

### \* 安装

```
npm install @diplodoc/translation
```

### • API

#### 翻译:

此函数从给定的标记下字符串中取出骨架和 XLF 字符串, 用于 QQ 计算机辅助翻译工具 。 QQ

```typescript
function extract(parameters: ExtractParameters): ExtractOutput;
```

#### 参数 `Object`

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `markdown` | `string` | 从中提取文本内容的标记下字符串 . |
| `source` | `LanguageLocale` | 源语言与地语. |
| `target` | `LanguageLocale` | 目标语言与地语. |
| `skeletonPath` | `string` | 放置骨架文件的路径 . |
| `markdownPath` | `string` | 标记下文件读取的路径 . |
| `filter` | `boolean` | 没有过滤可转换文件 . |
| `compact` | `boolean` | 压缩 XLIFF 无 `<g>` 包装 代码块是精确处理的,而不是整体处理. 标出一个整句会去到骨架上,标出它只停留在单元中开始或结束;一个句子可以从内线代码开始. |
| `code` | `string` | 如何处理有栅栏的代码,见下文. |
| `unitLocalIds` | `boolean` | 重新启动占位符 IDs (`g-N`编号 :`x-N`对于每个单位,而不是通过文档编号,所以一个单位的文本并不取决于上方的标记. 当单位文本作为翻译缓存密钥时使用. 默认关闭. |

#### QQ 代码块

这个 `code` 参数选择一个有栅栏的代码块的可转换度 :

| 模式 | 翻译的内容 |
| --- | --- |
| `no` | 没什么,块是复制的. |
| `all` | 整个街区 默认无 `compact`。 。 。 . |
| `precise` | `<placeholders>` 和评论 `bash`编号 :`shell`编号 :`sh` 块。 默认为 `compact`。 。 。 . |
| `adaptive` | 所有东西 `precise` 加上其他语文的行评论(`#`, (中文(简体) ), `//`, (中文(简体) ), `--`和标签 `mermaid` 图表。 注释出代码,工具指令和分隔符保持不变. |

单个块用其信息字符串来覆盖模式 : ` ```yaml translate=adaptive `。 。 。 .

#### QQ 类型

#### 语言本地化 `Object`

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `language` | `string` | 如ISO 639-1所描述的语言代码. |
| `locale` | `string` | 如ISO 3166-所描述的alpha-2格式的语言编码 1个 |

#### 摘录产出 `Object`

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `skeleton` | `string` | 提取出骨架串. |
| `xlf` | `string` | 提取出 XLF 字符串 . |
| `warnings` | `string[]` | 部分分解没有被翻译, 提取失败, 每行一行 。 例如,a `page-constructor` 块中无法解析YAML. |

#### 编曲 编曲

此函数由 QQ 从给定的 QQ 骨架和 XLF 翻译出 QQ 标记下.

```typescript
function compose(parameters: ComposeParameters): string
```

#### 参数 `Object`

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `skeleton` | `string` | 用散列来代替可变文本的骨架 |
| `xlf` | `string` | XLF 有翻译文本 |

### 使用量

#### 摘录

从下标记提取骨架和 xlf

#### 示例

```typescript
import {extract} from '@diplodoc/translation';

const markdown = `# Heading 1

Paragraph

- First list item
- Second list item

Heading 2
-----------

Paragraph with **bold text** and *italic*

> text inside of the blockquote

1. First ordered list item
2. Second ordered list item

[Link text](files/file.md "Link Description")

![Alternative image text](files/image.png "Image title")
`;

const params = {
    markdown,
    source: {language: 'en', locale: 'US' as const},
    target: {language: 'ru', locale: 'RU' as const},
    skeletonPath: 'path/where/you/will/put/generated/skeleton.skl.md',
    markdownPath: 'path/to/file/where/markdown/string/came/from.md',
}

const {skeleton, xlf} = extract(params);

console.log(skeleton);
console.log(xlf);
```

#### 输出

![skeleton output](https://npmcn.com/package/%40diplodoc/translation/assets/extract-output-skeleton.png "skeleton")

![xlf output](https://npmcn.com/package/%40diplodoc/translation/assets/extract-output-xlf.png "xlf")

#### 编曲

将骨架和 xlf 编成已翻译为下标记

#### 示例

```typescript
import {compose} from '@diplodoc/translation';

const skeleton = `%%%1%%%
%%%2%%%
- %%%3%%%
- %%%4%%%
%%%5%%%
-----------
%%%6%%%**%%%7%%%**%%%8%%%*%%%9%%%*
> %%%10%%%
1. %%%11%%%
2. %%%12%%%

[%%%13%%%](files/file.md "%%%14%%%")

![%%%15%%%](files/image.png "%%%16%%%")
`

const xlf = `<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
  <file original="text.md" source-language="ru-RU" target-language="en-US" datatype="markdown">
    <header>
      <skeleton>
        <external-file href="text.skl.md"></external-file>
      </skeleton>
    </header>
    <body>
      <trans-unit id="1">
        <source>Heading 1</source>
        <target>Заголовок 1</target>
      </trans-unit>
      <trans-unit id="2">
        <source>Paragraph</source>
        <target>Параграф</target>
      </trans-unit>
      <trans-unit id="3">
        <source>First list item</source>
        <target>Первый элемент списка</target>
      </trans-unit>
      <trans-unit id="4">
        <source>Second list item</source>
        <target>Второй элемент списка</target>
      </trans-unit>
      <trans-unit id="5">
        <source>Heading 2</source>
        <target>Заголовок 2</target>
      </trans-unit>
      <trans-unit id="6">
        <source>Paragraph with </source>
        <target>Параграф содержащий </target>
      </trans-unit>
      <trans-unit id="7">
        <source>bold text</source>
        <target>жирный текст</target>
      </trans-unit>
      <trans-unit id="8">
        <source> and </source>
        <target> и </target>
      </trans-unit>
      <trans-unit id="9">
        <source>italics</source>
        <target>курсив</target>
      </trans-unit>
      <trans-unit id="10">
        <source>text inside of the blockquote</source>
        <target>текст внутри цитаты</target>
      </trans-unit>
      <trans-unit id="11">
        <source>First ordered list item</source>
        <target>Первый элемент нумерованного списка</target>
      </trans-unit>
      <trans-unit id="12">
        <source>Second ordered list item</source>
        <target>Второй элемент нумерованного списка</target>
      </trans-unit>
      <trans-unit id="13">
        <source>Link text</source>
        <target>Текст ссылки</target>
      </trans-unit>
      <trans-unit id="14">
        <source>Link Description</source>
        <target>Описание ссылки</target>
      </trans-unit>
      <trans-unit id="15">
        <source>Alternative image text</source>
        <target>Альтернативный текст картинки</target>
      </trans-unit>
      <trans-unit id="16">
        <source>Image title</source>
        <target>Титул картинки</target>
      </trans-unit>
    </body>
  </file>
</xliff>
`;

const markdown = compose({skeleton, xlf});

console.log(markdown);
```

#### 输出

![markdown output](https://npmcn.com/package/%40diplodoc/translation/assets/compose-output-markdown.png "markdown")

## 常见问题

### @diplodoc/translation 是什么？

减额翻译设施

### 如何安装 @diplodoc/translation？

在项目目录运行 npm install @diplodoc/translation，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：markdown-it（^13\.0\.2）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @diplodoc/translation 支持 TypeScript 吗？

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

### @diplodoc/translation 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @diplodoc/translation 需要什么版本的 Node\.js？

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

### @diplodoc/translation 可以商用吗？

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

### @diplodoc/translation 的下载量有多少？

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

### @diplodoc/translation 还在维护吗？

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

