Merge branch '2.4' into 2.5
* 2.4: [Translator] Use quote to surround invalid locale Optimize assertLocale regexp [ExpressionLanguage] Fixed an issue with # characters in double quoted string literals Add some tweaks to the pt_BR translations [Validator] Backported #11410 to 2.3: Object initializers are called only once per object [Translator][FrameworkBundle] Added @ to the list of allowed chars in Translator [Process] Reduce I/O load on Windows platform [Form] Check if IntlDateFormatter constructor returned a valid object before using it Conflicts: src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php
This commit is contained in:
commit
feb4f5cdb6
@ -46,7 +46,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'));
|
||||||
@ -56,6 +56,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()
|
||||||
@ -63,7 +64,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'));
|
||||||
@ -73,12 +74,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'));
|
||||||
@ -88,6 +90,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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,6 +192,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;
|
||||||
}
|
}
|
||||||
@ -220,6 +230,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;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class Lexer
|
|||||||
|
|
||||||
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
|
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
|
||||||
++$cursor;
|
++$cursor;
|
||||||
} elseif (preg_match('/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As', $expression, $match, null, $cursor)) {
|
} elseif (preg_match('/"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As', $expression, $match, null, $cursor)) {
|
||||||
// strings
|
// strings
|
||||||
$tokens[] = new Token(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)), $cursor + 1);
|
$tokens[] = new Token(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)), $cursor + 1);
|
||||||
$cursor += strlen($match[0]);
|
$cursor += strlen($match[0]);
|
||||||
|
@ -78,6 +78,14 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(new Token('operator', '..', 1)),
|
array(new Token('operator', '..', 1)),
|
||||||
'..',
|
'..',
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
array(new Token('string', '#foo', 1)),
|
||||||
|
"'#foo'",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(new Token('string', '#foo', 1)),
|
||||||
|
'"#foo"',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,8 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
* Returns a preconfigured IntlDateFormatter instance
|
* Returns a preconfigured IntlDateFormatter instance
|
||||||
*
|
*
|
||||||
* @return \IntlDateFormatter
|
* @return \IntlDateFormatter
|
||||||
|
*
|
||||||
|
* @throws TransformationFailedException in case the date formatter can not be constructed.
|
||||||
*/
|
*/
|
||||||
protected function getIntlDateFormatter()
|
protected function getIntlDateFormatter()
|
||||||
{
|
{
|
||||||
@ -162,6 +164,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
$pattern = $this->pattern;
|
$pattern = $this->pattern;
|
||||||
|
|
||||||
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
|
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
|
||||||
|
|
||||||
|
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
|
||||||
|
if (!$intlDateFormatter) {
|
||||||
|
throw new TransformationFailedException(intl_get_error_message(), intl_get_error_code());
|
||||||
|
}
|
||||||
|
|
||||||
$intlDateFormatter->setLenient(false);
|
$intlDateFormatter->setLenient(false);
|
||||||
|
|
||||||
return $intlDateFormatter;
|
return $intlDateFormatter;
|
||||||
|
@ -77,6 +77,12 @@ class DateType extends AbstractType
|
|||||||
$calendar,
|
$calendar,
|
||||||
$pattern
|
$pattern
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
|
||||||
|
if (!$formatter) {
|
||||||
|
throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
|
||||||
|
}
|
||||||
|
|
||||||
$formatter->setLenient(false);
|
$formatter->setLenient(false);
|
||||||
|
|
||||||
if ('choice' === $options['widget']) {
|
if ('choice' === $options['widget']) {
|
||||||
|
@ -306,6 +306,8 @@ class ProcessPipes
|
|||||||
private function readStreams($blocking, $close = false)
|
private function readStreams($blocking, $close = false)
|
||||||
{
|
{
|
||||||
if (empty($this->pipes)) {
|
if (empty($this->pipes)) {
|
||||||
|
usleep(Process::TIMEOUT_PRECISION * 1E4);
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,7 +652,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
$duration = microtime(true) - $start;
|
$duration = microtime(true) - $start;
|
||||||
|
|
||||||
$this->assertLessThan($timeout + Process::TIMEOUT_PRECISION, $duration);
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
// Windows is a bit slower as it read file handles, then allow twice the precision
|
||||||
|
$maxDuration = $timeout + 2 * Process::TIMEOUT_PRECISION;
|
||||||
|
} else {
|
||||||
|
$maxDuration = $timeout + Process::TIMEOUT_PRECISION;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertLessThan($maxDuration, $duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckTimeoutOnNonStartedProcess()
|
public function testCheckTimeoutOnNonStartedProcess()
|
||||||
|
@ -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(
|
||||||
@ -430,6 +428,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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,8 +318,8 @@ class Translator implements TranslatorInterface
|
|||||||
*/
|
*/
|
||||||
private function assertValidLocale($locale)
|
private function assertValidLocale($locale)
|
||||||
{
|
{
|
||||||
if (0 !== preg_match('/[^a-z0-9_\\.\\-]+/i', $locale, $match)) {
|
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Invalid locale: %s.', $locale));
|
throw new \InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,11 +280,11 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="73">
|
<trans-unit id="73">
|
||||||
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
||||||
<target>O formato da imagem é muito grande ({{ ratio }}). O formato máximo é {{ max_ratio }}.</target>
|
<target>A proporção da imagem é muito grande ({{ ratio }}). A proporção máxima permitida é {{ max_ratio }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="74">
|
<trans-unit id="74">
|
||||||
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
||||||
<target>O formato da imagem é muito pequeno ({{ ratio }}). O formato mínimo esperado é {{ min_ratio }}.</target>
|
<target>A proporção da imagem é muito pequena ({{ ratio }}). A proporção mínima esperada é {{ min_ratio }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="75">
|
<trans-unit id="75">
|
||||||
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
||||||
@ -300,7 +300,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="78">
|
<trans-unit id="78">
|
||||||
<source>An empty file is not allowed.</source>
|
<source>An empty file is not allowed.</source>
|
||||||
<target>Ficheiro vazio não é permitido.</target>
|
<target>Arquivo vazio não é permitido.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
|
Reference in New Issue
Block a user