Skip to content

Commit fd755b4

Browse files
committed
feature #31248 [Translator] Add sources when dumping qt files (Stadly)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Translator] Add sources when dumping qt files | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This PR implements similar functionality as #30909, but for Qt files. Currently, only the Qt element `location` is supported, so only `sources` metadata is included in the dump. Commits ------- ff7577d Add sources when dumping qt files
2 parents 7cd1bdd + ff7577d commit fd755b4

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

src/Symfony/Component/Translation/Dumper/QtFileDumper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti
3333

3434
foreach ($messages->all($domain) as $source => $target) {
3535
$message = $context->appendChild($dom->createElement('message'));
36+
$metadata = $messages->getMetadata($source, $domain);
37+
if (isset($metadata['sources'])) {
38+
foreach ((array) $metadata['sources'] as $location) {
39+
$loc = explode(':', $location, 2);
40+
$location = $message->appendChild($dom->createElement('location'));
41+
$location->setAttribute('filename', $loc[0]);
42+
if (isset($loc[1])) {
43+
$location->setAttribute('line', $loc[1]);
44+
}
45+
}
46+
}
3647
$message->appendChild($dom->createElement('source', $source));
3748
$message->appendChild($dom->createElement('translation', $target));
3849
}

src/Symfony/Component/Translation/Tests/Dumper/QtFileDumperTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,26 @@ class QtFileDumperTest extends TestCase
2020
public function testFormatCatalogue()
2121
{
2222
$catalogue = new MessageCatalogue('en');
23-
$catalogue->add(['foo' => 'bar'], 'resources');
23+
$catalogue->add(['foo' => 'bar', 'foo_bar' => 'foobar', 'bar_foo' => 'barfoo'], 'resources');
24+
$catalogue->setMetadata('foo_bar', [
25+
'comments' => [
26+
'Comment 1',
27+
'Comment 2',
28+
],
29+
'flags' => [
30+
'fuzzy',
31+
'another',
32+
],
33+
'sources' => [
34+
'src/file_1',
35+
'src/file_2:50',
36+
],
37+
], 'resources');
38+
$catalogue->setMetadata('bar_foo', [
39+
'comments' => 'Comment',
40+
'flags' => 'fuzzy',
41+
'sources' => 'src/file_1',
42+
], 'resources');
2443

2544
$dumper = new QtFileDumper();
2645

src/Symfony/Component/Translation/Tests/Loader/QtFileLoaderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public function testLoad()
2323
$resource = __DIR__.'/../fixtures/resources.ts';
2424
$catalogue = $loader->load($resource, 'en', 'resources');
2525

26-
$this->assertEquals(['foo' => 'bar'], $catalogue->all('resources'));
26+
$this->assertEquals([
27+
'foo' => 'bar',
28+
'foo_bar' => 'foobar',
29+
'bar_foo' => 'barfoo',
30+
], $catalogue->all('resources'));
2731
$this->assertEquals('en', $catalogue->getLocale());
2832
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
2933
}

src/Symfony/Component/Translation/Tests/fixtures/resources.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@
66
<source>foo</source>
77
<translation>bar</translation>
88
</message>
9+
<message>
10+
<location filename="src/file_1"/>
11+
<location filename="src/file_2" line="50"/>
12+
<source>foo_bar</source>
13+
<translation>foobar</translation>
14+
</message>
15+
<message>
16+
<location filename="src/file_1"/>
17+
<source>bar_foo</source>
18+
<translation>barfoo</translation>
19+
</message>
920
</context>
1021
</TS>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy