Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation] XLIFF Add id to meta data. #18762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
XLIFF Add id to meta data.
  • Loading branch information
SpacePossum committed May 12, 2016
commit 74b221ccb95856be728aa5c1c2b98fce010f8f8a
11 changes: 9 additions & 2 deletions 11 src/Symfony/Component/Translation/Loader/XliffFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
$metadata['notes'] = $notes;
}

if (isset($translation->target) && $translation->target->attributes()) {
$metadata['target-attributes'] = array();
foreach ($translation->target->attributes() as $key => $value) {
$metadata['target-attributes'][$key] = (string) $value;
}
}

if (isset($attributes['id'])) {
$metadata['id'] = (string) $attributes['id'];
}

$catalogue->setMetadata((string) $source, $metadata, $domain);
}
}
Expand Down Expand Up @@ -214,6 +219,7 @@ private function fixXmlLocation($schemaSource, $xmlUri)
$parts = explode('/', str_replace('\\', '/', $tmpfile));
}
}

$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
$newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));

Expand All @@ -232,7 +238,7 @@ private function getXmlErrors($internalErrors)
$errors = array();
foreach (libxml_get_errors() as $error) {
$errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)',
LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
LIBXML_ERR_WARNING === $error->level ? 'WARNING' : 'ERROR',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, I'll revert it 👍

$error->code,
trim($error->message),
$error->file ?: 'n/a',
Expand Down Expand Up @@ -280,7 +286,7 @@ private function getVersionNumber(\DOMDocument $dom)
return '1.2';
}

/*
/**
* @param \SimpleXMLElement|null $noteElement
* @param string|null $encoding
*
Expand All @@ -294,6 +300,7 @@ private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $enco
return $notes;
}

/** @var \SimpleXMLElement $xmlNote */
foreach ($noteElement as $xmlNote) {
$noteAttributes = $xmlNote->attributes();
$note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testEncoding()

$this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
$this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
$this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz')))), $catalogue->getMetadata('foo', 'domain1'));
$this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz'))), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
}

public function testTargetAttributesAreStoredCorrectly()
Expand Down Expand Up @@ -142,11 +142,11 @@ public function testLoadNotes()
$loader = new XliffFileLoader();
$catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');

$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo'))), $catalogue->getMetadata('foo', 'domain1'));
$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo')), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
// message without target
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo'))), $catalogue->getMetadata('extra', 'domain1'));
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo')), 'id' => '2'), $catalogue->getMetadata('extra', 'domain1'));
// message with empty target
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux')), 'id' => '123'), $catalogue->getMetadata('key', 'domain1'));
}

public function testLoadVersion2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<source>extra</source>
<note from="foo">bar</note>
</trans-unit>
<trans-unit id="3">
<trans-unit id="123">
<source>key</source>
<target></target>
<note>baz</note>
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.