changed the default XLIFF extension to .xlf instead of .xliff (this is BC and .xliff files are still valid)
This commit is contained in:
parent
7e9d53bc93
commit
2cb6260d07
@ -198,6 +198,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
|
|||||||
|
|
||||||
### Translation
|
### Translation
|
||||||
|
|
||||||
|
* changed the default extension for XLIFF files from .xliff to .xlf
|
||||||
* added support for gettext
|
* added support for gettext
|
||||||
* added support for more than one fallback locale
|
* added support for more than one fallback locale
|
||||||
* added support for translations in ResourceBundles
|
* added support for translations in ResourceBundles
|
||||||
|
@ -25,13 +25,18 @@ class TranslatorPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$loaders = array();
|
$loaders = array();
|
||||||
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
|
||||||
$loaders[$id] = $attributes[0]['alias'];
|
$loaders[$id][] = $attributes[0]['alias'];
|
||||||
|
if (isset($attributes[0]['legacy-alias'])) {
|
||||||
|
$loaders[$id][] = $attributes[0]['legacy-alias'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($container->hasDefinition('translation.loader')) {
|
if ($container->hasDefinition('translation.loader')) {
|
||||||
$definition = $container->getDefinition('translation.loader');
|
$definition = $container->getDefinition('translation.loader');
|
||||||
foreach ($loaders as $id => $format) {
|
foreach ($loaders as $id => $formats) {
|
||||||
$definition->addMethodCall('addLoader', array($format, new Reference($id)));
|
foreach ($formats as $format) {
|
||||||
|
$definition->addMethodCall('addLoader', array($format, new Reference($id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="translation.loader.xliff" class="%translation.loader.xliff.class%">
|
<service id="translation.loader.xliff" class="%translation.loader.xliff.class%">
|
||||||
<tag name="translation.loader" alias="xliff" />
|
<tag name="translation.loader" alias="xlf" legacy-alias="xliff" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="translation.loader.po" class="%translation.loader.po.class%">
|
<service id="translation.loader.po" class="%translation.loader.po.class%">
|
||||||
@ -89,7 +89,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="tranlsation.dumper.xliff" class="%translation.dumper.xliff.class%">
|
<service id="tranlsation.dumper.xliff" class="%translation.dumper.xliff.class%">
|
||||||
<tag name="translation.dumper" alias="xliff" />
|
<tag name="translation.dumper" alias="xlf" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="translation.dumper.po" class="%translation.dumper.po.class%">
|
<service id="translation.dumper.po" class="%translation.dumper.po.class%">
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
|
||||||
|
|
||||||
|
class TranslatorPassTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testValidCollector()
|
||||||
|
{
|
||||||
|
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||||
|
$definition->expects($this->at(0))
|
||||||
|
->method('addMethodCall')
|
||||||
|
->with('addLoader', array('xliff', new Reference('xliff')));
|
||||||
|
$definition->expects($this->at(1))
|
||||||
|
->method('addMethodCall')
|
||||||
|
->with('addLoader', array('xlf', new Reference('xliff')));
|
||||||
|
|
||||||
|
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||||
|
$container->expects($this->any())
|
||||||
|
->method('hasDefinition')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$container->expects($this->once())
|
||||||
|
->method('getDefinition')
|
||||||
|
->will($this->returnValue($definition));
|
||||||
|
$container->expects($this->once())
|
||||||
|
->method('findTaggedServiceIds')
|
||||||
|
->will($this->returnValue(array('xliff' => array(array('alias' => 'xliff', 'legacy-alias' => 'xlf')))));
|
||||||
|
$container->expects($this->once())
|
||||||
|
->method('findDefinition')
|
||||||
|
->will($this->returnValue($this->getMock('Symfony\Component\DependencyInjection\Definition')));
|
||||||
|
;
|
||||||
|
|
||||||
|
$pass = new TranslatorPass();
|
||||||
|
$pass->process($container);
|
||||||
|
}
|
||||||
|
}
|
@ -148,7 +148,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
realpath(__DIR__.'/../../Resources/translations/validators.fr.xliff'),
|
realpath(__DIR__.'/../../Resources/translations/validators.fr.xlf'),
|
||||||
array_map(function($resource) use ($resources) { return realpath($resource[1]); }, $resources),
|
array_map(function($resource) use ($resources) { return realpath($resource[1]); }, $resources),
|
||||||
'->registerTranslatorConfiguration() finds FrameworkExtension translation resources'
|
'->registerTranslatorConfiguration() finds FrameworkExtension translation resources'
|
||||||
);
|
);
|
||||||
|
@ -55,6 +55,6 @@ class XliffFileDumper extends FileDumper
|
|||||||
*/
|
*/
|
||||||
protected function getExtension()
|
protected function getExtension()
|
||||||
{
|
{
|
||||||
return 'xliff';
|
return 'xlf';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dumper = new XliffFileDumper();
|
$dumper = new XliffFileDumper();
|
||||||
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
|
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
|
||||||
|
|
||||||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.xliff'), file_get_contents($tempDir.'/messages.en.xliff'));
|
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.xlf'), file_get_contents($tempDir.'/messages.en.xlf'));
|
||||||
|
|
||||||
unlink($tempDir.'/messages.en.xliff');
|
unlink($tempDir.'/messages.en.xlf');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testLoad()
|
public function testLoad()
|
||||||
{
|
{
|
||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$resource = __DIR__.'/../fixtures/resources.xliff';
|
$resource = __DIR__.'/../fixtures/resources.xlf';
|
||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||||
@ -42,7 +42,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testLoadResourceDoesNotValidate()
|
public function testLoadResourceDoesNotValidate()
|
||||||
{
|
{
|
||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/non-valid.xliff', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testLoadThrowsAnExceptionIfFileNotLocal()
|
public function testLoadThrowsAnExceptionIfFileNotLocal()
|
||||||
{
|
{
|
||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$resource = 'http://example.com/resources.xliff';
|
$resource = 'http://example.com/resources.xlf';
|
||||||
$loader->load($resource, 'en', 'domain1');
|
$loader->load($resource, 'en', 'domain1');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user