Skip to content

Instantly share code, notes, and snippets.

@tabuna
Created April 24, 2018 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabuna/dc5f59237f0c54897de93aa45aee261c to your computer and use it in GitHub Desktop.
Save tabuna/dc5f59237f0c54897de93aa45aee261c to your computer and use it in GitHub Desktop.
Сравнение XLF
<?php
/**
* Class DiffXLF
*/
class DiffXLF
{
/**
* @var array
*/
private $first = [];
/**
* @var array
*/
private $secondary = [];
/**
* @param $file
*
* @return array
*/
private function load($file): array
{
$xml = new SimpleXMLElement(file_get_contents($file));
return $this->fillKeys($xml);
}
/**
* @param SimpleXMLElement $XMLElement
*
* @return array
*/
private function fillKeys(SimpleXMLElement $XMLElement)
{
foreach ($XMLElement->file->body->children() as $item) {
$ids[] = (string) $item->attributes()->id;
}
return $ids ?? [];
}
/**
* @param $first
* @param $secondary
*
* @return array
*/
public function diff($first, $secondary)
{
$this->first = $this->load($first);
$this->secondary = $this->load($secondary);
return array_merge(
array_diff($this->first, $this->secondary),
array_diff($this->secondary, $this->first)
);
}
}
$diff = new DiffXLF();
$diff = $diff->diff('messages.en.xlf', 'messages.ru.xlf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment