$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
- foreach ($xml->xpath('//xliff:unit/xliff:segment') as $segment) {
- $source = $segment->source;
-
- // If the xlf file has another encoding specified, try to convert it because
- // simple_xml will always return utf-8 encoded values
- $target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding);
-
- $catalogue->set((string) $source, $target, $domain);
+ foreach ($xml->xpath('//xliff:unit') as $unit) {
+ foreach ($unit->segment as $segment) {
+ $source = $segment->source;
+
+ // If the xlf file has another encoding specified, try to convert it because
+ // simple_xml will always return utf-8 encoded values
+ $target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding);
+
+ $catalogue->set((string) $source, $target, $domain);
+
+ $metadata = array();
+ if (isset($segment->target) && $segment->target->attributes()) {
+ $metadata['target-attributes'] = array();
+ foreach ($segment->target->attributes() as $key => $value) {
+ $metadata['target-attributes'][$key] = (string) $value;
+ }
+ }
- $metadata = array();
- if (isset($segment->target) && $segment->target->attributes()) {
- $metadata['target-attributes'] = array();
- foreach ($segment->target->attributes() as $key => $value) {
- $metadata['target-attributes'][$key] = (string) $value;
+ if (isset($unit->notes)) {
+ $metadata['notes'] = array();
+ foreach ($unit->notes->note as $noteNode) {
+ $note = array();
+ foreach ($noteNode->attributes() as $key => $value) {
+ $note[$key] = (string) $value;
+ }
+ $note['content'] = (string) $noteNode;
+ $metadata['notes'][] = $note;
+ }
}
- }
- $catalogue->setMetadata((string) $source, $metadata, $domain);
+ $catalogue->setMetadata((string) $source, $metadata, $domain);
+ }
}
}
{
$newPath = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
$parts = explode('/', $newPath);
+ $locationstart = 'file:///';
if (0 === stripos($newPath, 'phar://')) {
- $tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
+ $tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
if ($tmpfile) {
copy($newPath, $tmpfile);
$parts = explode('/', str_replace('\\', '/', $tmpfile));
+ } else {
+ array_shift($parts);
+ $locationstart = 'phar:///';
}
}
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
- $newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
+ $newPath = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts));
return str_replace($xmlUri, $newPath, $schemaSource);
}
$namespace = $xliff->attributes->getNamedItem('xmlns');
if ($namespace) {
- if (substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34) !== 0) {
+ if (0 !== substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34)) {
throw new InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
}