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:
Fabien Potencier 2014-07-17 12:20:14 +02:00
commit efab88490e
3 changed files with 16 additions and 6 deletions

View File

@ -45,7 +45,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
{
$translator = $this->getTranslator($this->getLoader());
$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('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('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
}
public function testTransWithCaching()
@ -62,7 +63,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
// prime the cache
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir));
$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('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('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
$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
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
$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('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('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
}
public function testGetLocale()
@ -185,6 +188,13 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
'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;
}
@ -216,6 +226,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese
$translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese
$translator->addResource('loader', 'foo', 'fr.UTF-8');
$translator->addResource('loader', 'foo', 'sr@latin'); // Latin Serbian
return $translator;
}

View File

@ -103,7 +103,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar (fr)', $translator->trans('bar'));
}
/**
* @dataProvider getInvalidLocalesTests
* @expectedException \InvalidArgumentException
@ -329,7 +328,6 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
// no assertion. this method just asserts that no exception is thrown
}
public function getTransFileTests()
{
return array(
@ -429,6 +427,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
array('fr_FR'),
array('fr.FR'),
array('fr-FR.UTF8'),
array('sr@latin'),
);
}

View File

@ -308,7 +308,7 @@ class Translator implements TranslatorInterface
*/
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));
}
}