Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Translation] Added template for relative file paths
- Loading branch information
Showing
6 changed files
with
143 additions
and
28 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
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
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
38 changes: 38 additions & 0 deletions
38
src/Symfony/Component/Translation/Dumper/NullFileDumper.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,38 @@ | ||
<?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; | ||
|
||
/** | ||
* Null file dumper used for testing purposes. | ||
* | ||
* @author Florian Voutzinos <florian@voutzinos.com> | ||
*/ | ||
class NullFileDumper extends FileDumper | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function format(MessageCatalogue $messages, $domain) | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getExtension() | ||
{ | ||
return 'null'; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
src/Symfony/Component/Translation/Tests/Dumper/NullFileDumperTest.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,57 @@ | ||
<?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\Tests\Dumper; | ||
|
||
use Symfony\Component\Translation\Dumper\NullFileDumper; | ||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
class NullFileDumperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDumpBackupsFileIfExisting() | ||
{ | ||
$tempDir = sys_get_temp_dir(); | ||
$file = $tempDir.'/messages.en.null'; | ||
$backupFile = $file.'~'; | ||
|
||
@touch($file); | ||
|
||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar')); | ||
|
||
$dumper = new NullFileDumper(); | ||
$dumper->dump($catalogue, array('path' => $tempDir)); | ||
|
||
$this->assertTrue(file_exists($backupFile)); | ||
|
||
@unlink($file); | ||
@unlink($backupFile); | ||
} | ||
|
||
public function testDumpCreatesNestedDirectoriesAndFile() | ||
{ | ||
$tempDir = sys_get_temp_dir(); | ||
$translationsDir = $tempDir.'/test/translations'; | ||
$file = $translationsDir.'/messages.en.null'; | ||
|
||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar')); | ||
|
||
$dumper = new NullFileDumper(); | ||
$dumper->setRelativePathTemplate('test/translations/{domain}.{locale}.{extension}'); | ||
$dumper->dump($catalogue, array('path' => $tempDir)); | ||
|
||
$this->assertTrue(file_exists($file)); | ||
|
||
@unlink($file); | ||
@rmdir($translationsDir); | ||
} | ||
} |