From 4ac380e016178c09e8671c306c69ae8ab73d0964 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 4 Sep 2011 20:43:59 +0200 Subject: [PATCH] Adjust QtTranslations patch and include QtTranslationsDumper + test aswell --- .../Resources/config/translation.xml | 10 +++-- .../Dumper/QtTranslationsDumper.php | 39 +++++++++++++++++++ .../Translation/Dumper/QtDumperTest.php | 29 ++++++++++++++ .../Translation/fixtures/resources.ts | 16 ++++---- 4 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 src/Symfony/Component/Translation/Dumper/QtTranslationsDumper.php create mode 100644 tests/Symfony/Tests/Component/Translation/Dumper/QtDumperTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index bb51aed42285..e03321fac016 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -15,6 +15,7 @@ Symfony\Component\Translation\Dumper\PhpDumper Symfony\Component\Translation\Dumper\XliffDumper Symfony\Component\Translation\Dumper\YamlDumper + Symfony\Component\Translation\Dumper\QtDumper @@ -47,10 +48,10 @@ -<<<<<<< HEAD -======= + + @@ -61,7 +62,10 @@ ->>>>>>> symfony/master + + + + diff --git a/src/Symfony/Component/Translation/Dumper/QtTranslationsDumper.php b/src/Symfony/Component/Translation/Dumper/QtTranslationsDumper.php new file mode 100644 index 000000000000..024cffdd4e43 --- /dev/null +++ b/src/Symfony/Component/Translation/Dumper/QtTranslationsDumper.php @@ -0,0 +1,39 @@ + + * + * 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 + */ +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(); + } +} diff --git a/tests/Symfony/Tests/Component/Translation/Dumper/QtDumperTest.php b/tests/Symfony/Tests/Component/Translation/Dumper/QtDumperTest.php new file mode 100644 index 000000000000..9966a52c7f38 --- /dev/null +++ b/tests/Symfony/Tests/Component/Translation/Dumper/QtDumperTest.php @@ -0,0 +1,29 @@ + + * + * 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); + } +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts b/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts index 1e03f03db369..40e18522c85b 100644 --- a/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts +++ b/tests/Symfony/Tests/Component/Translation/fixtures/resources.ts @@ -1,10 +1,10 @@ - + - - resources - - foo - bar - - + + resources + + foo + bar + +