Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust QtTranslations patch and include QtTranslationsDumper + test a…
…swell
- Loading branch information
Showing
4 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Symfony/Component/Translation/Dumper/QtTranslationsDumper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Dumper; | ||
|
||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
/** | ||
* QtTranslationsDumper generates a TS/XML formated string representation of a message catalogue | ||
* | ||
* @author Benjamin Eberlei <kontakt@beberlei.de> | ||
*/ | ||
class QtTranslationsDumper implements DumperInterface | ||
{ | ||
public function dump(MessageCatalogue $messages, $domain = 'messages') | ||
{ | ||
$dom = new \DOMDocument('1.0', 'utf-8'); | ||
$dom->formatOutput = true; | ||
$ts = $dom->appendChild($dom->createElement('TS')); | ||
$context = $ts->appendChild($dom->createElement('context')); | ||
$context->appendChild($dom->createElement('name', $domain)); | ||
|
||
foreach ($messages->all($domain) as $source => $target) { | ||
$message = $context->appendChild($dom->createElement('message')); | ||
$message->appendChild($dom->createElement('source', $source)); | ||
$message->appendChild($dom->createElement('translation', $target)); | ||
} | ||
|
||
return $dom->saveXML(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Symfony/Tests/Component/Translation/Dumper/QtDumperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\Translation\Dumper; | ||
|
||
use Symfony\Component\Translation\MessageCatalogue; | ||
use Symfony\Component\Translation\Dumper\QtTranslationsDumper; | ||
|
||
class QtTranslationsDumperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDump() | ||
{ | ||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar'), 'resources'); | ||
|
||
$dumper = new QtTranslationsDumper(); | ||
$dumperString = $dumper->dump($catalogue, 'resources'); | ||
|
||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ts'), $dumperString); | ||
} | ||
} |
16 changes: 8 additions & 8 deletions
16
tests/Symfony/Tests/Component/Translation/fixtures/resources.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<TS> | ||
<context> | ||
<name>resources</name> | ||
<message> | ||
<source>foo</source> | ||
<translation>bar</translation> | ||
</message> | ||
</context> | ||
<context> | ||
<name>resources</name> | ||
<message> | ||
<source>foo</source> | ||
<translation>bar</translation> | ||
</message> | ||
</context> | ||
</TS> |