Skip to content

Installation

phil/translation-memory

Requirements

RequirementWhy
PHP 8.5 or laterReadonly classes, typed constants, new without parentheses
ext-ctypeThe subtags of a language tag told apart, letters or digits
ext-dom and ext-libxmlXLIFF, TMX and TBX written and read on PHP's DOM
ext-mbstringOffsets, lengths and distances counted in code points
phil/ujoThe documents cut into segments and put back together
phil/text-diffWhat changed in the source of a stale segment
phil/fontsThe character map of a template's font, for the check of the characters it draws

Installing

composer require phil/translation-memory

It is a library, not a bundle: there is nothing to register. Its services hold no state between two calls — build them once and keep them:

use Phil\TranslationMemory\Memory\InMemoryStore;
use Phil\TranslationMemory\Memory\TranslationMemory;
use Phil\TranslationMemory\Segmentation\Granularity;
use Phil\TranslationMemory\Segmentation\UjoSegmenter;

$segmenter = new UjoSegmenter(Granularity::Block);
$memory = new TranslationMemory(new InMemoryStore(), minimum: 0.7, limit: 5);

The memory needs a store: InMemoryStore for tests and small memories loaded from a file, or an implementation of MemoryStore over the application's database. In a Symfony application, phil/translation-bundle provides a Doctrine store, keeps the segments and wires everything as services.