定制 opencat/xliff 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

opencat/xliff

Composer 安装命令:

composer require opencat/xliff

包简介

XLIFF 1.2 writer and reader for the OpenCAT Framework

README 文档

README

XLIFF 1.2 writer and reader for the OpenCAT Framework.

Serialises a BilingualDocument to XLIFF 1.2 (plus a companion .skl skeleton file) and reads it back. XLIFF is the interchange format between the extraction/segmentation phase and the translation phase — it can be sent to a translator or a TMS and then read back to rebuild the translated file.

Installation

composer require opencat/xliff

Requires ext-dom and ext-libxml.

Writing XLIFF

use CatFramework\Xliff\XliffWriter;

$writer = new XliffWriter();
$writer->write($doc, 'project.xlf');
// Also writes project.xlf.skl (JSON skeleton — required for rebuild)

Reading XLIFF

use CatFramework\Xliff\XliffReader;

$reader = new XliffReader();
$doc = $reader->read('project.xlf');
// Loads the .skl file automatically (expects project.xlf.skl alongside)

// Rebuild the original file format
$filter->rebuild($doc, 'translated-output.docx');

XLIFF output format

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:catfw="urn:catframework">
  <file original="report.docx" source-language="en-US" target-language="fr-FR" datatype="x-unknown">
    <header>
      <skl><external-file href="project.xlf.skl"/></skl>
    </header>
    <body>
      <trans-unit id="seg-1" translate="yes">
        <source>Hello <bpt id="1" rid="b1">&lt;strong&gt;</bpt>world<ept id="2" rid="b1">&lt;/strong&gt;</ept>!</source>
        <target state="translated">Bonjour <bpt id="1" rid="b1">&lt;strong&gt;</bpt>monde<ept id="2" rid="b1">&lt;/strong&gt;</ept>!</target>
      </trans-unit>
    </body>
  </file>
</xliff>

Inline code mapping

InlineCode objects are serialised as XLIFF inline elements:

InlineCode isIsolated XLIFF element
OPENING false <bpt rid="…">
CLOSING false <ept rid="…">
STANDALONE false <ph rid="…">
OPENING true <it pos="open" rid="…">
CLOSING true <it pos="close" rid="…">

The catfw:equiv-text attribute carries InlineCode::$displayText when set, giving CAT tools a human-readable hint (e.g. <b> instead of the raw <strong> tag).

Segment status mapping

SegmentStatus XLIFF state
Untranslated new
Draft new
Translated translated
Reviewed signed-off
Approved final
Rejected needs-translation

Locked segments (SegmentPair::$isLocked = true) are written with translate="no".

Skeleton file

The .skl file is a JSON-encoded copy of BilingualDocument::$skeleton — the filter-specific data needed to rebuild the original file. It is written alongside the XLIFF and must remain with it. The reader looks for {xliffPath}.skl automatically.

Related packages

  • opencat/coreBilingualDocument, SegmentPair, Segment, InlineCode
  • opencat/workflow — calls XliffWriter as the final step in the processing pipeline

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固