diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index 8b2661e9ba437..db18db0ee1b7f 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * deprecated Translator::getMessages(), use TranslatorBagInterface::getCatalogue() instead. * added options 'as_tree', 'inline' to YamlFileDumper + * added option 'json_encoding' to JsonFileDumper 2.7.0 ----- diff --git a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php index 7ad35184cd55e..ab410481899ab 100644 --- a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php @@ -20,12 +20,26 @@ */ class JsonFileDumper extends FileDumper { + /** + * {@inheritdoc} + */ + protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()) + { + if (isset($options['json_encoding'])) { + $flags = $options['json_encoding']; + } else { + $flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; + } + + return json_encode($messages->all($domain), $flags); + } + /** * {@inheritdoc} */ public function format(MessageCatalogue $messages, $domain = 'messages') { - return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); + return $this->formatCatalogue($messages, $domain); } /** diff --git a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php index 697cd939f607a..8f5314f6fa511 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php @@ -23,13 +23,13 @@ public function testDump() } $catalogue = new MessageCatalogue('en'); - $catalogue->add(array('foo' => 'bar')); + $catalogue->add(array('foo' => '"bar"')); $tempDir = sys_get_temp_dir(); $dumper = new JsonFileDumper(); - $dumper->dump($catalogue, array('path' => $tempDir)); + $dumper->dump($catalogue, array('path' => $tempDir, 'json_encoding' => JSON_HEX_QUOT)); - $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($tempDir.'/messages.en.json')); + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.dump.json'), file_get_contents($tempDir.'/messages.en.json')); unlink($tempDir.'/messages.en.json'); } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/resources.dump.json b/src/Symfony/Component/Translation/Tests/fixtures/resources.dump.json new file mode 100644 index 0000000000000..335965d592cab --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/fixtures/resources.dump.json @@ -0,0 +1 @@ +{"foo":"\u0022bar\u0022"} \ No newline at end of file
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: