1. Go to this page and download the library: Download vivomedia/xliff library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vivomedia / xliff example snippets
use VIVOMEDIA\XliffParser\Domain\V12\TransUnit;
use VIVOMEDIA\XliffParser\Reader\V12\XliffReader;
$reader = new XliffReader();
$document = $reader->read('/path/to/file.xlf');
foreach ($read->getFiles() as $file) {
foreach ($file->getBodyItems() as $bodyItem) {
if ($bodyItem instanceof TransUnit) {
printf(
"'%s' | '%s' => '%s'\n",
$bodyItem->getAttributes()->get('id'),
$bodyItem->getSource()->getContent(),
$bodyItem->getTarget()?->getContent(),
);
}
}
}
use VIVOMEDIA\XliffParser\Domain\V12\Attributes;
use VIVOMEDIA\XliffParser\Domain\V12\Document;
use VIVOMEDIA\XliffParser\Domain\V12\File;
use VIVOMEDIA\XliffParser\Domain\V12\Source;use VIVOMEDIA\XliffParser\Domain\V12\Target;use VIVOMEDIA\XliffParser\Domain\V12\TransUnit;
use VIVOMEDIA\XliffParser\Writer\V12\XliffWriter;
$b = new XliffWriter();
$b->write($read, $pathES);
$sourceAttributes = new Attributes(["xml" => ['lang' => "de"]]);
$source = new Source("Bitte übersetzen", $sourceAttributes);
$targetAttributes = new Attributes([null => ['state' => 'translated'], "xml" => ['lang' => "en"]]);
$target = new Target("Please translate", $targetAttributes);
$transUnitAttributes = new Attributes([null => ['id' => "my.identifier", "approved" => "yes"]]);
$transUnitItem = new TransUnit($source, $target, $transUnitAttributes);
$fileAttributes = new Attributes([null => ['product-name' => "MyProduct", "source-language" => "de", "target-language" => "en"]]);
$file = new File([$transUnitItem], $fileAttributes);
$document = new Document([$file]);
$writer = new XliffWriter();
$writer->write($document, '/path/to/other.xlf');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.