8000 [Translation][File dumper] allow get file content without writing in file. by aitboudad · Pull Request #15786 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation][File dumper] allow get file content without writing in file. #15786

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

Merged
merged 2 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Translation][File dumper] allow get file content without writing in …
…file.
  • Loading branch information
aitboudad committed Sep 21, 2015
commit 9b877cfa2351fdb95b7244c895bbc55893fc16c7
1 change: 1 addition & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* deprecated FileDumper::format(), overwrite FileDumper::formatCatalogue() instead.
* deprecated Translator::getMessages(), rely on TranslatorBagInterface::getCatalogue() instead.
* added `FileDumper::formatCatalogue` which allows format the catalogue without dumping it into file.
* added option `json_encoding` to JsonFileDumper
* added options `as_tree`, `inline` to YamlFileDumper
* added support for XLIFF 2.0.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/CsvFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$handle = fopen('php://memory', 'rb+');

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/FileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function dump(MessageCatalogue $messages, $options = array())
*
* @return string representation
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
@trigger_error('The '.__METHOD__.' method will replace the format method in 3.0. You should overwritten it instead of overwriting format instead.', E_USER_DEPRECATED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$data = $indexes = $resources = '';

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/IniFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
if (isset($options['json_encoding'])) {
$flags = $options['json_encoding'];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/MoFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
$offsets = array();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/PhpFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function format(MessageCatalogue $messages, $domain)
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$output = "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/PoFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$output = 'msgid ""'."\n";
$output .= 'msgstr ""'."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Dumper/QtFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function format(MessageCatalogue $messages, $domain)
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class XliffFileDumper extends FileDumper
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$xliffVersion = '1.2';
if (array_key_exists('xliff_version', $options)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class YamlFileDumper extends FileDumper
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@

class CsvFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar', 'bar' => 'foo
foo', 'foo;foo' => 'bar'));

$tempDir = sys_get_temp_dir();
$dumper = new CsvFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/valid.csv'), file_get_contents($tempDir.'/messages.en.csv'));

unlink($tempDir.'/messages.en.csv');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/valid.csv', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@

class FileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
{
$tempDir = sys_get_temp_dir();

$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$dumper = new ConcreteFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertTrue(file_exists($tempDir.'/messages.en.concrete'));
}

public function testDumpBackupsFileIfExisting()
{
$tempDir = sys_get_temp_dir();
Expand Down Expand Up @@ -58,7 +71,7 @@ public function testDumpCreatesNestedDirectoriesAndFile()

class ConcreteFileDumper extends FileDumper
{
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IcuResFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
if (!function_exists('mb_convert_encoding')) {
$this->markTestSkipped('This test requires mbstring to work.');
Expand All @@ -25,14 +25,8 @@ public function testDump()
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$tempDir = sys_get_temp_dir().'/IcuResFileDumperTest';
$dumper = new IcuResFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resourcebundle/res/en.res'), file_get_contents($tempDir.'/messages/en.res'));

@unlink($tempDir.'/messages/en.res');
@rmdir($tempDir.'/messages');
@rmdir($tempDir);
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resourcebundle/res/en.res', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

class IniFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$tempDir = sys_get_temp_dir();
$dumper = new IniFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ini'), file_get_contents($tempDir.'/messages.en.ini'));

unlink($tempDir.'/messages.en.ini');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.ini', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@

class JsonFileDumperTest extends \PHPUnit_Framework_TestCase
{
private $tempDir;

protected function setUp()
{
$this->tempDir = sys_get_temp_dir();
}

protected function tearDown()
{
unlink($this->tempDir.'/messages.en.json');
}

public function testDump()
public function testFormatCatalogue()
{
if (PHP_VERSION_ID < 50400) {
$this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing');
Expand All @@ -38,9 +26,8 @@ public function testDump()
$catalogue->add(array('foo' => 'bar'));

$dumper = new JsonFileDumper();
$dumper->dump($catalogue, array('path' => $this->tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($this->tempDir.'/messages.en.json'));
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.json', $dumper->formatCatalogue($catalogue, 'messages'));
}

public function testDumpWithCustomEncoding()
Expand All @@ -49,8 +36,7 @@ public function testDumpWithCustomEncoding()
$catalogue->add(array('foo' => '"bar"'));

$dumper = new JsonFileDumper();
$dumper->dump($catalogue, array('path' => $this->tempDir, 'json_encoding' => JSON_HEX_QUOT));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.dump.json'), file_get_contents($this->tempDir.'/messages.en.json'));
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', array('json_encoding' => JSON_HEX_QUOT)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

class MoFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$tempDir = sys_get_temp_dir();
$dumper = new MoFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.mo'), file_get_contents($tempDir.'/messages.en.mo'));

unlink($tempDir.'/messages.en.mo');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.mo', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

class PhpFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$tempDir = sys_get_temp_dir();
$dumper = new PhpFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.php'), file_get_contents($tempDir.'/messages.en.php'));

unlink($tempDir.'/messages.en.php');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.php', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

class PoFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'));

$tempDir = sys_get_temp_dir();
$dumper = new PoFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.po'), file_get_contents($tempDir.'/messages.en.po'));

unlink($tempDir.'/messages.en.po');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.po', $dumper->formatCatalogue($catalogue, 'messages'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

class QtFileDumperTest extends \PHPUnit_Framework_TestCase
{
public function testDump()
public function testFormatCatalogue()
{
$catalogue = new MessageCatalogue('en');
$catalogue->add(array('foo' => 'bar'), 'resources');

$tempDir = sys_get_temp_dir();
$dumper = new QtFileDumper();
$dumper->dump($catalogue, array('path' => $tempDir));

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ts'), file_get_contents($tempDir.'/resources.en.ts'));

unlink($tempDir.'/resources.en.ts');
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.ts', $dumper->formatCatalogue($catalogue, 'resources'));
}
}
Loading
0