Skip to content
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

[Translator] Add sources when dumping qt files #31248

Merged
merged 1 commit into from Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Symfony/Component/Translation/Dumper/QtFileDumper.php
Expand Up @@ -33,6 +33,17 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti

foreach ($messages->all($domain) as $source => $target) {
$message = $context->appendChild($dom->createElement('message'));
$metadata = $messages->getMetadata($source, $domain);
if (isset($metadata['sources'])) {
foreach ((array) $metadata['sources'] as $location) {
fabpot marked this conversation as resolved.
Show resolved Hide resolved
$loc = explode(':', $location, 2);
$location = $message->appendChild($dom->createElement('location'));
$location->setAttribute('filename', $loc[0]);
if (isset($loc[1])) {
$location->setAttribute('line', $loc[1]);
}
}
}
$message->appendChild($dom->createElement('source', $source));
$message->appendChild($dom->createElement('translation', $target));
}
Expand Down
Expand Up @@ -20,7 +20,26 @@ class QtFileDumperTest extends TestCase
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(['foo' => 'bar'], 'resources');
$catalogue->add(['foo' => 'bar', 'foo_bar' => 'foobar', 'bar_foo' => 'barfoo'], 'resources');
$catalogue->setMetadata('foo_bar', [
'comments' => [
'Comment 1',
'Comment 2',
],
'flags' => [
'fuzzy',
'another',
],
'sources' => [
'src/file_1',
'src/file_2:50',
],
], 'resources');
$catalogue->setMetadata('bar_foo', [
'comments' => 'Comment',
'flags' => 'fuzzy',
'sources' => 'src/file_1',
], 'resources');

$dumper = new QtFileDumper();

Expand Down
Expand Up @@ -23,7 +23,11 @@ public function testLoad()
$resource = __DIR__.'/../fixtures/resources.ts';
$catalogue = $loader->load($resource, 'en', 'resources');

$this->assertEquals(['foo' => 'bar'], $catalogue->all('resources'));
$this->assertEquals([
'foo' => 'bar',
'foo_bar' => 'foobar',
'bar_foo' => 'barfoo',
], $catalogue->all('resources'));
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
}
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Translation/Tests/fixtures/resources.ts
Expand Up @@ -6,5 +6,16 @@
<source>foo</source>
<translation>bar</translation>
</message>
<message>
<location filename="src/file_1"/>
<location filename="src/file_2" line="50"/>
<source>foo_bar</source>
<translation>foobar</translation>
</message>
<message>
<location filename="src/file_1"/>
<source>bar_foo</source>
<translation>barfoo</translation>
</message>
</context>
</TS>