PHPackages                             opencat/tmx - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. opencat/tmx

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

opencat/tmx
===========

TMX 1.4b parser and writer for the OpenCAT Framework

00PHP

Since May 9Pushed 1mo agoCompare

[ Source](https://github.com/shaikhammar/opencat-tmx)[ Packagist](https://packagist.org/packages/opencat/tmx)[ RSS](/packages/opencat-tmx/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

opencat/tmx
===========

[](#opencattmx)

TMX 1.4b parser and writer for the [OpenCAT Framework](https://github.com/shaikhammar/opencat-framework).

Converts between TMX files and `TranslationUnit` objects. Used by [`opencat/translation-memory`](https://github.com/shaikhammar/opencat-framework/tree/main/packages/translation-memory) for import and export. You can also use it standalone for TMX manipulation.

Installation
------------

[](#installation)

```
composer require opencat/tmx
```

Requires `ext-dom`, `ext-libxml`, and `ext-xmlreader`.

Reading TMX files
-----------------

[](#reading-tmx-files)

### DOM mode — small files (up to ~10,000 TUs)

[](#dom-mode--small-files-up-to-10000-tus)

```
use CatFramework\Tmx\TmxReader;

$reader = new TmxReader();
$units = $reader->read('memory.tmx');  // returns TranslationUnit[]

foreach ($units as $unit) {
    echo $unit->sourceLanguage . ' → ' . $unit->targetLanguage . PHP_EOL;
    echo $unit->source->getPlainText() . PHP_EOL;
    echo $unit->target->getPlainText() . PHP_EOL;
}
```

### Streaming mode — large files (100k+ TUs)

[](#streaming-mode--large-files-100k-tus)

Uses `XMLReader` internally; yields one `TranslationUnit` at a time without loading the full document into memory.

```
foreach ($reader->stream('large-memory.tmx') as $unit) {
    // process $unit — only one TU is in memory at a time
    $tm->store($unit);
}
```

Writing TMX files
-----------------

[](#writing-tmx-files)

```
use CatFramework\Tmx\TmxWriter;
use CatFramework\Core\Model\TranslationUnit;

$writer = new TmxWriter();
$writer->write($units, 'exported.tmx');  // $units is TranslationUnit[]
```

Inline code support
-------------------

[](#inline-code-support)

TMX inline elements are mapped to `InlineCode` objects:

TMX elementInlineCode typeNotes```OPENING`Begin paired tag (bold open, link open, etc.)```CLOSING`End paired tag```STANDALONE`Standalone placeholder (line break, etc.)```OPENING`, isolatedIsolated tag (tag boundary crossed a TU)```CLOSING`, isolatedIsolated tagThe `i` attribute is used as the `InlineCode::$id` pairing key (equivalent to XLIFF's `rid`).

Language matching
-----------------

[](#language-matching)

The `srclang` attribute on the `` determines which `` is the source. Matching is:

1. Exact case-insensitive match (`"en-US"` == `"EN-US"`)
2. Prefix match (`srclang="en"` matches `xml:lang="en-US"`)
3. First `` if no match

TMX file structure
------------------

[](#tmx-file-structure)

```

DOCTYPE tmx SYSTEM "tmx14.dtd">

      Legal
      Source text.
      Texte cible.

```

`` elements are stored in `TranslationUnit::$metadata`. The `creationid` attribute maps to `TranslationUnit::$createdBy`.

Related packages
----------------

[](#related-packages)

- [`opencat/core`](https://github.com/shaikhammar/opencat-framework/tree/main/packages/core) — `TranslationUnit`, `Segment`, `InlineCode`
- [`opencat/translation-memory`](https://github.com/shaikhammar/opencat-framework/tree/main/packages/translation-memory) — uses `TmxReader::stream()` for `import()` and `TmxWriter` for `export()`

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance61

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6b9044413071860fd6199e56c661a24f449797b77a1b130f0df7e98be8481f4?d=identicon)[shaikhammar](/maintainers/shaikhammar)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (4 commits)")

### Embed Badge

![Health badge](/badges/opencat-tmx/health.svg)

```
[![Health](https://phpackages.com/badges/opencat-tmx/health.svg)](https://phpackages.com/packages/opencat-tmx)
```

###  Alternatives

[sskaje/mqtt

sskaje's MQTT Class

8769.9k1](/packages/sskaje-mqtt)[zfr/hydrator

Zend Framework 3 prototype for a better hydrator component

1512.0k](/packages/zfr-hydrator)[agence-adeliom/easy-editor-bundle

A Symfony bundle for EasyAdmin that provide a flexible content editor

1111.3k1](/packages/agence-adeliom-easy-editor-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
