bug #11403 [Translator][FrameworkBundle] Added @ to the list of allowed chars in Translator (takeit)
This PR was squashed before being merged into the 2.3 branch (closes #11403).
Discussion
----------
[Translator][FrameworkBundle] Added @ to the list of allowed chars in Translator
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #11396
| License | MIT
Commits
-------
3176f8b
[Translator][FrameworkBundle] Added @ to the list of allowed chars in Translator
This commit is contained in:
commit
efab88490e
@ -45,7 +45,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$translator = $this->getTranslator($this->getLoader());
|
$translator = $this->getTranslator($this->getLoader());
|
||||||
$translator->setLocale('fr');
|
$translator->setLocale('fr');
|
||||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8'));
|
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||||
|
|
||||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
@ -55,6 +55,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||||
|
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransWithCaching()
|
public function testTransWithCaching()
|
||||||
@ -62,7 +63,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
// prime the cache
|
// prime the cache
|
||||||
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
|
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
|
||||||
$translator->setLocale('fr');
|
$translator->setLocale('fr');
|
||||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8'));
|
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||||
|
|
||||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
@ -72,12 +73,13 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||||
|
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||||
|
|
||||||
// do it another time as the cache is primed now
|
// do it another time as the cache is primed now
|
||||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
||||||
$translator->setLocale('fr');
|
$translator->setLocale('fr');
|
||||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8'));
|
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||||
|
|
||||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||||
@ -87,6 +89,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||||
|
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetLocale()
|
public function testGetLocale()
|
||||||
@ -185,6 +188,13 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'foobarbaz' => 'foobarbaz (fr.UTF-8)',
|
'foobarbaz' => 'foobarbaz (fr.UTF-8)',
|
||||||
))))
|
))))
|
||||||
;
|
;
|
||||||
|
$loader
|
||||||
|
->expects($this->at(6))
|
||||||
|
->method('load')
|
||||||
|
->will($this->returnValue($this->getCatalogue('sr@latin', array(
|
||||||
|
'foobarbax' => 'foobarbax (sr@latin)',
|
||||||
|
))))
|
||||||
|
;
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
@ -216,6 +226,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese
|
$translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese
|
||||||
$translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese
|
$translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese
|
||||||
$translator->addResource('loader', 'foo', 'fr.UTF-8');
|
$translator->addResource('loader', 'foo', 'fr.UTF-8');
|
||||||
|
$translator->addResource('loader', 'foo', 'sr@latin'); // Latin Serbian
|
||||||
|
|
||||||
return $translator;
|
return $translator;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('bar (fr)', $translator->trans('bar'));
|
$this->assertEquals('bar (fr)', $translator->trans('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidLocalesTests
|
* @dataProvider getInvalidLocalesTests
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
@ -329,7 +328,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
// no assertion. this method just asserts that no exception is thrown
|
// no assertion. this method just asserts that no exception is thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getTransFileTests()
|
public function getTransFileTests()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -429,6 +427,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('fr_FR'),
|
array('fr_FR'),
|
||||||
array('fr.FR'),
|
array('fr.FR'),
|
||||||
array('fr-FR.UTF8'),
|
array('fr-FR.UTF8'),
|
||||||
|
array('sr@latin'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ class Translator implements TranslatorInterface
|
|||||||
*/
|
*/
|
||||||
private function assertValidLocale($locale)
|
private function assertValidLocale($locale)
|
||||||
{
|
{
|
||||||
if (0 !== preg_match('/[^a-z0-9_\\.\\-]+/i', $locale, $match)) {
|
if (0 !== preg_match('/[^a-z0-9@_\\.\\-]+/i', $locale, $match)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Invalid locale: %s.', $locale));
|
throw new \InvalidArgumentException(sprintf('Invalid locale: %s.', $locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user