composer update
This commit is contained in:
@@ -53,6 +53,20 @@ class MergeOperationTest extends AbstractOperationTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultFromIntlDomain()
|
||||
{
|
||||
$this->assertEquals(
|
||||
new MessageCatalogue('en', array(
|
||||
'messages' => array('a' => 'old_a', 'b' => 'old_b'),
|
||||
'messages+intl-icu' => array('d' => 'old_d', 'c' => 'new_c'),
|
||||
)),
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'), 'messages+intl-icu' => array('d' => 'old_d'))),
|
||||
new MessageCatalogue('en', array('messages+intl-icu' => array('a' => 'new_a', 'c' => 'new_c')))
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMetadata()
|
||||
{
|
||||
$leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b')));
|
||||
|
@@ -53,6 +53,20 @@ class TargetOperationTest extends AbstractOperationTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultFromIntlDomain()
|
||||
{
|
||||
$this->assertEquals(
|
||||
new MessageCatalogue('en', array(
|
||||
'messages' => array('a' => 'old_a'),
|
||||
'messages+intl-icu' => array('c' => 'new_c'),
|
||||
)),
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a'), 'messages+intl-icu' => array('b' => 'old_b'))),
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'new_a'), 'messages+intl-icu' => array('c' => 'new_c')))
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMetadata()
|
||||
{
|
||||
$leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b')));
|
||||
|
@@ -40,6 +40,38 @@ class XliffLintCommandTest extends TestCase
|
||||
$this->assertContains('OK', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
public function testLintCorrectFiles()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$filename1 = $this->createFile();
|
||||
$filename2 = $this->createFile();
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => array($filename1, $filename2)),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
|
||||
$this->assertContains('OK', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideStrictFilenames
|
||||
*/
|
||||
public function testStrictFilenames($requireStrictFileNames, $fileNamePattern, $targetLanguage, $mustFail)
|
||||
{
|
||||
$tester = $this->createCommandTester($requireStrictFileNames);
|
||||
$filename = $this->createFile('note', $targetLanguage, $fileNamePattern);
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => $filename),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
);
|
||||
|
||||
$this->assertEquals($mustFail ? 1 : 0, $tester->getStatusCode());
|
||||
$this->assertContains($mustFail ? '[WARNING] 0 XLIFF files have valid syntax and 1 contain errors.' : '[OK] All 1 XLIFF files contain valid syntax.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testLintIncorrectXmlSyntax()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
@@ -59,7 +91,7 @@ class XliffLintCommandTest extends TestCase
|
||||
$tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
|
||||
$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
|
||||
$this->assertContains('There is a mismatch between the file extension ("en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
|
||||
$this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +134,7 @@ EOF;
|
||||
/**
|
||||
* @return string Path to the new file
|
||||
*/
|
||||
private function createFile($sourceContent = 'note', $targetLanguage = 'en')
|
||||
private function createFile($sourceContent = 'note', $targetLanguage = 'en', $fileNamePattern = 'messages.%locale%.xlf')
|
||||
{
|
||||
$xliffContent = <<<XLIFF
|
||||
<?xml version="1.0"?>
|
||||
@@ -118,7 +150,7 @@ EOF;
|
||||
</xliff>
|
||||
XLIFF;
|
||||
|
||||
$filename = sprintf('%s/translation-xliff-lint-test/messages.en.xlf', sys_get_temp_dir());
|
||||
$filename = sprintf('%s/translation-xliff-lint-test/%s', sys_get_temp_dir(), str_replace('%locale%', 'en', $fileNamePattern));
|
||||
file_put_contents($filename, $xliffContent);
|
||||
|
||||
$this->files[] = $filename;
|
||||
@@ -129,11 +161,11 @@ XLIFF;
|
||||
/**
|
||||
* @return CommandTester
|
||||
*/
|
||||
private function createCommandTester($application = null)
|
||||
private function createCommandTester($requireStrictFileNames = true, $application = null)
|
||||
{
|
||||
if (!$application) {
|
||||
$application = new Application();
|
||||
$application->add(new XliffLintCommand());
|
||||
$application->add(new XliffLintCommand(null, null, null, $requireStrictFileNames));
|
||||
}
|
||||
|
||||
$command = $application->find('lint:xliff');
|
||||
@@ -160,4 +192,16 @@ XLIFF;
|
||||
}
|
||||
rmdir(sys_get_temp_dir().'/translation-xliff-lint-test');
|
||||
}
|
||||
|
||||
public function provideStrictFilenames()
|
||||
{
|
||||
yield array(false, 'messages.%locale%.xlf', 'en', false);
|
||||
yield array(false, 'messages.%locale%.xlf', 'es', true);
|
||||
yield array(false, '%locale%.messages.xlf', 'en', false);
|
||||
yield array(false, '%locale%.messages.xlf', 'es', true);
|
||||
yield array(true, 'messages.%locale%.xlf', 'en', false);
|
||||
yield array(true, 'messages.%locale%.xlf', 'es', true);
|
||||
yield array(true, '%locale%.messages.xlf', 'en', true);
|
||||
yield array(true, '%locale%.messages.xlf', 'es', true);
|
||||
}
|
||||
}
|
||||
|
@@ -42,85 +42,85 @@ class TranslationDataCollectorTest extends TestCase
|
||||
{
|
||||
$collectedMessages = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'transChoiceNumber' => 3,
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'transChoiceNumber' => 3,
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 4, '%foo%' => 'bar'),
|
||||
'transChoiceNumber' => 4,
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 4, '%foo%' => 'bar'),
|
||||
'transChoiceNumber' => 4,
|
||||
),
|
||||
);
|
||||
$expectedMessages = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'count' => 3,
|
||||
'parameters' => array(
|
||||
array('%count%' => 3),
|
||||
array('%count%' => 3),
|
||||
array('%count%' => 4, '%foo%' => 'bar'),
|
||||
),
|
||||
'transChoiceNumber' => 3,
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'count' => 3,
|
||||
'parameters' => array(
|
||||
array('%count%' => 3),
|
||||
array('%count%' => 3),
|
||||
array('%count%' => 4, '%foo%' => 'bar'),
|
||||
),
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
);
|
||||
|
||||
|
@@ -25,56 +25,80 @@ class DataCollectorTranslatorTest extends TestCase
|
||||
|
||||
$collector->trans('foo');
|
||||
$collector->trans('bar');
|
||||
$collector->transChoice('choice', 0);
|
||||
$collector->trans('choice', array('%count%' => 0));
|
||||
$collector->trans('bar_ru');
|
||||
$collector->trans('bar_ru', array('foo' => 'bar'));
|
||||
|
||||
$expectedMessages = array();
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 0),
|
||||
'transChoiceNumber' => 0,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array('foo' => 'bar'),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedMessages, $collector->getCollectedMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testCollectMessagesTransChoice()
|
||||
{
|
||||
$collector = $this->createCollector();
|
||||
$collector->setFallbackLocales(array('fr', 'ru'));
|
||||
$collector->transChoice('choice', 0);
|
||||
|
||||
$expectedMessages = array();
|
||||
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array(),
|
||||
'parameters' => array('%count%' => 0),
|
||||
'transChoiceNumber' => 0,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array('foo' => 'bar'),
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedMessages, $collector->getCollectedMessages());
|
||||
}
|
||||
|
@@ -32,6 +32,30 @@ class FileDumperTest extends TestCase
|
||||
@unlink($tempDir.'/messages.en.concrete');
|
||||
}
|
||||
|
||||
public function testDumpIntl()
|
||||
{
|
||||
$tempDir = sys_get_temp_dir();
|
||||
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'), 'd1');
|
||||
$catalogue->add(array('bar' => 'foo'), 'd1+intl-icu');
|
||||
$catalogue->add(array('bar' => 'foo'), 'd2+intl-icu');
|
||||
|
||||
$dumper = new ConcreteFileDumper();
|
||||
@unlink($tempDir.'/d2.en.concrete');
|
||||
$dumper->dump($catalogue, array('path' => $tempDir));
|
||||
|
||||
$this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar');
|
||||
@unlink($tempDir.'/d1.en.concrete');
|
||||
|
||||
$this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo');
|
||||
@unlink($tempDir.'/d1+intl-icu.en.concrete');
|
||||
|
||||
$this->assertFileNotExists($tempDir.'/d2.en.concrete');
|
||||
$this->assertStringEqualsFile($tempDir.'/d2+intl-icu.en.concrete', 'bar=foo');
|
||||
@unlink($tempDir.'/d2+intl-icu.en.concrete');
|
||||
}
|
||||
|
||||
public function testDumpCreatesNestedDirectoriesAndFile()
|
||||
{
|
||||
$tempDir = sys_get_temp_dir();
|
||||
@@ -56,7 +80,7 @@ class ConcreteFileDumper extends FileDumper
|
||||
{
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
return '';
|
||||
return http_build_query($messages->all($domain), '', '&');
|
||||
}
|
||||
|
||||
protected function getExtension()
|
||||
|
96
vendor/symfony/translation/Tests/Formatter/IntlFormatterTest.php
vendored
Normal file
96
vendor/symfony/translation/Tests/Formatter/IntlFormatterTest.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Formatter;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Formatter\IntlFormatter;
|
||||
use Symfony\Component\Translation\Formatter\IntlFormatterInterface;
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
*/
|
||||
class IntlFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideDataForFormat
|
||||
*/
|
||||
public function testFormat($expected, $message, $arguments)
|
||||
{
|
||||
$this->assertEquals($expected, trim((new IntlFormatter())->formatIntl($message, 'en', $arguments)));
|
||||
}
|
||||
|
||||
public function testInvalidFormat()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
(new IntlFormatter())->formatIntl('{foo', 'en', array(2));
|
||||
}
|
||||
|
||||
public function testFormatWithNamedArguments()
|
||||
{
|
||||
if (version_compare(INTL_ICU_VERSION, '4.8', '<')) {
|
||||
$this->markTestSkipped('Format with named arguments can only be run with ICU 4.8 or higher and PHP >= 5.5');
|
||||
}
|
||||
|
||||
$chooseMessage = <<<'_MSG_'
|
||||
{gender_of_host, select,
|
||||
female {{num_guests, plural, offset:1
|
||||
=0 {{host} does not give a party.}
|
||||
=1 {{host} invites {guest} to her party.}
|
||||
=2 {{host} invites {guest} and one other person to her party.}
|
||||
other {{host} invites {guest} as one of the # people invited to her party.}}}
|
||||
male {{num_guests, plural, offset:1
|
||||
=0 {{host} does not give a party.}
|
||||
=1 {{host} invites {guest} to his party.}
|
||||
=2 {{host} invites {guest} and one other person to his party.}
|
||||
other {{host} invites {guest} as one of the # people invited to his party.}}}
|
||||
other {{num_guests, plural, offset:1
|
||||
=0 {{host} does not give a party.}
|
||||
=1 {{host} invites {guest} to their party.}
|
||||
=2 {{host} invites {guest} and one other person to their party.}
|
||||
other {{host} invites {guest} as one of the # people invited to their party.}}}}
|
||||
_MSG_;
|
||||
|
||||
$message = (new IntlFormatter())->formatIntl($chooseMessage, 'en', array(
|
||||
'gender_of_host' => 'male',
|
||||
'num_guests' => 10,
|
||||
'host' => 'Fabien',
|
||||
'guest' => 'Guilherme',
|
||||
));
|
||||
|
||||
$this->assertEquals('Fabien invites Guilherme as one of the 9 people invited to his party.', $message);
|
||||
}
|
||||
|
||||
public function provideDataForFormat()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'There is one apple',
|
||||
'There is one apple',
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
'4,560 monkeys on 123 trees make 37.073 monkeys per tree',
|
||||
'{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree',
|
||||
array(4560, 123, 4560 / 123),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testPercentsAndBracketsAreTrimmed()
|
||||
{
|
||||
$formatter = new IntlFormatter();
|
||||
$this->assertInstanceof(IntlFormatterInterface::class, $formatter);
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', array('name' => 'Fab')));
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', array('%name%' => 'Fab')));
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', array('{{ name }}' => 'Fab')));
|
||||
}
|
||||
}
|
@@ -26,6 +26,7 @@ class MessageFormatterTest extends TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceMessages
|
||||
* @group legacy
|
||||
*/
|
||||
public function testFormatPlural($expected, $message, $number, $parameters)
|
||||
{
|
||||
|
@@ -11,86 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Symfony\Component\Translation\IdentityTranslator;
|
||||
use Symfony\Contracts\Tests\Translation\TranslatorTest;
|
||||
|
||||
class IdentityTranslatorTest extends TestCase
|
||||
class IdentityTranslatorTest extends TranslatorTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTransTests
|
||||
*/
|
||||
public function testTrans($expected, $id, $parameters)
|
||||
public function getTranslator()
|
||||
{
|
||||
$translator = new IdentityTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
public function testTransChoiceWithExplicitLocale($expected, $id, $number, $parameters)
|
||||
{
|
||||
$translator = new IdentityTranslator();
|
||||
$translator->setLocale('en');
|
||||
|
||||
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
public function testTransChoiceWithDefaultLocale($expected, $id, $number, $parameters)
|
||||
{
|
||||
\Locale::setDefault('en');
|
||||
|
||||
$translator = new IdentityTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters));
|
||||
}
|
||||
|
||||
public function testGetSetLocale()
|
||||
{
|
||||
$translator = new IdentityTranslator();
|
||||
$translator->setLocale('en');
|
||||
|
||||
$this->assertEquals('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
public function testGetLocaleReturnsDefaultLocaleIfNotSet()
|
||||
{
|
||||
// in order to test with "pt_BR"
|
||||
IntlTestHelper::requireFullIntl($this, false);
|
||||
|
||||
$translator = new IdentityTranslator();
|
||||
|
||||
\Locale::setDefault('en');
|
||||
$this->assertEquals('en', $translator->getLocale());
|
||||
|
||||
\Locale::setDefault('pt_BR');
|
||||
$this->assertEquals('pt_BR', $translator->getLocale());
|
||||
}
|
||||
|
||||
public function getTransTests()
|
||||
{
|
||||
return array(
|
||||
array('Symfony is great!', 'Symfony is great!', array()),
|
||||
array('Symfony is awesome!', 'Symfony is %what%!', array('%what%' => 'awesome')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTransChoiceTests()
|
||||
{
|
||||
return array(
|
||||
array('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0, array('%count%' => 0)),
|
||||
array('There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1, array('%count%' => 1)),
|
||||
array('There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10, array('%count%' => 10)),
|
||||
array('There are 0 apples', 'There is 1 apple|There are %count% apples', 0, array('%count%' => 0)),
|
||||
array('There is 1 apple', 'There is 1 apple|There are %count% apples', 1, array('%count%' => 1)),
|
||||
array('There are 10 apples', 'There is 1 apple|There are %count% apples', 10, array('%count%' => 10)),
|
||||
// custom validation messages may be coded with a fixed value
|
||||
array('There are 2 apples', 'There are 2 apples', 2, array('%count%' => 2)),
|
||||
);
|
||||
return new IdentityTranslator();
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,9 @@ namespace Symfony\Component\Translation\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Translation\Interval;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class IntervalTest extends TestCase
|
||||
{
|
||||
/**
|
||||
|
@@ -66,7 +66,7 @@ class XliffFileLoaderTest extends TestCase
|
||||
$loader = new XliffFileLoader();
|
||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'), $catalogue->all('domain1'));
|
||||
}
|
||||
|
||||
public function testIncompleteResource()
|
||||
|
@@ -21,17 +21,19 @@ class LoggingTranslatorTest extends TestCase
|
||||
public function testTransWithNoTranslationIsLogged()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger->expects($this->exactly(2))
|
||||
$logger->expects($this->exactly(1))
|
||||
->method('warning')
|
||||
->with('Translation not found.')
|
||||
;
|
||||
|
||||
$translator = new Translator('ar');
|
||||
$loggableTranslator = new LoggingTranslator($translator, $logger);
|
||||
$loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
|
||||
$loggableTranslator->trans('bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceFallbackIsLogged()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
@@ -47,4 +49,20 @@ class LoggingTranslatorTest extends TestCase
|
||||
$loggableTranslator = new LoggingTranslator($translator, $logger);
|
||||
$loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceWithNoTranslationIsLogged()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger->expects($this->exactly(1))
|
||||
->method('warning')
|
||||
->with('Translation not found.')
|
||||
;
|
||||
|
||||
$translator = new Translator('ar');
|
||||
$loggableTranslator = new LoggingTranslator($translator, $logger);
|
||||
$loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,9 @@ class MessageCatalogueTest extends TestCase
|
||||
|
||||
public function testGetDomains()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array(), 'domain2' => array()));
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array(), 'domain2' => array(), 'domain2+intl-icu' => array(), 'domain3+intl-icu' => array()));
|
||||
|
||||
$this->assertEquals(array('domain1', 'domain2'), $catalogue->getDomains());
|
||||
$this->assertEquals(array('domain1', 'domain2', 'domain3'), $catalogue->getDomains());
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
@@ -37,24 +37,43 @@ class MessageCatalogueTest extends TestCase
|
||||
$this->assertEquals(array('foo' => 'foo'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(array(), $catalogue->all('domain88'));
|
||||
$this->assertEquals($messages, $catalogue->all());
|
||||
|
||||
$messages = array('domain1+intl-icu' => array('foo' => 'bar')) + $messages + array(
|
||||
'domain2+intl-icu' => array('bar' => 'foo'),
|
||||
'domain3+intl-icu' => array('biz' => 'biz'),
|
||||
);
|
||||
$catalogue = new MessageCatalogue('en', $messages);
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(array('bar' => 'foo'), $catalogue->all('domain2'));
|
||||
$this->assertEquals(array('biz' => 'biz'), $catalogue->all('domain3'));
|
||||
|
||||
$messages = array(
|
||||
'domain1' => array('foo' => 'bar'),
|
||||
'domain2' => array('bar' => 'foo'),
|
||||
'domain3' => array('biz' => 'biz'),
|
||||
);
|
||||
$this->assertEquals($messages, $catalogue->all());
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2+intl-icu' => array('bar' => 'bar')));
|
||||
|
||||
$this->assertTrue($catalogue->has('foo', 'domain1'));
|
||||
$this->assertTrue($catalogue->has('bar', 'domain2'));
|
||||
$this->assertFalse($catalogue->has('bar', 'domain1'));
|
||||
$this->assertFalse($catalogue->has('foo', 'domain88'));
|
||||
}
|
||||
|
||||
public function testGetSet()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'), 'domain2+intl-icu' => array('bar' => 'foo')));
|
||||
$catalogue->set('foo1', 'foo1', 'domain1');
|
||||
|
||||
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
|
||||
$this->assertEquals('foo', $catalogue->get('bar', 'domain2'));
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
@@ -75,7 +94,7 @@ class MessageCatalogueTest extends TestCase
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain1+intl-icu' => array('bar' => 'bar')));
|
||||
$catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1');
|
||||
|
||||
$this->assertEquals($messages, $catalogue->all('domain1'));
|
||||
@@ -89,16 +108,18 @@ class MessageCatalogueTest extends TestCase
|
||||
$r1 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
|
||||
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
|
||||
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo')));
|
||||
$catalogue->addResource($r);
|
||||
|
||||
$catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo1' => 'foo1')));
|
||||
$catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo1' => 'foo1'), 'domain2+intl-icu' => array('bar' => 'bar')));
|
||||
$catalogue1->addResource($r1);
|
||||
|
||||
$catalogue->addCatalogue($catalogue1);
|
||||
|
||||
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
|
||||
$this->assertEquals('bar', $catalogue->get('bar', 'domain2'));
|
||||
$this->assertEquals('bar', $catalogue->get('bar', 'domain2+intl-icu'));
|
||||
|
||||
$this->assertEquals(array($r, $r1), $catalogue->getResources());
|
||||
}
|
||||
|
@@ -14,6 +14,9 @@ namespace Symfony\Component\Translation\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Translation\MessageSelector;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class MessageSelectorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
|
@@ -26,6 +26,8 @@ use Symfony\Component\Translation\PluralizationRules;
|
||||
* The goal to cover all languages is to far fetched so this test case is smaller.
|
||||
*
|
||||
* @author Clemens Tolboom clemens@build2be.nl
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class PluralizationRulesTest extends TestCase
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@ class TranslatorCacheTest extends TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->tmpDir = sys_get_temp_dir().'/sf2_translation';
|
||||
$this->tmpDir = sys_get_temp_dir().'/sf_translation';
|
||||
$this->deleteTmpDir();
|
||||
}
|
||||
|
||||
@@ -66,13 +66,17 @@ class TranslatorCacheTest extends TestCase
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, new ArrayLoader());
|
||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||
$translator->addResource($format, array($msgid.'+intl' => 'OK'), $locale, 'messages+intl-icu');
|
||||
$translator->trans($msgid);
|
||||
$translator->trans($msgid.'+intl', array(), 'messages+intl-icu');
|
||||
|
||||
// Try again and see we get a valid result whilst no loader can be used
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, $this->createFailingLoader());
|
||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||
$translator->addResource($format, array($msgid.'+intl' => 'OK'), $locale, 'messages+intl-icu');
|
||||
$this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
|
||||
$this->assertEquals('OK', $translator->trans($msgid.'+intl', array(), 'messages+intl-icu'));
|
||||
}
|
||||
|
||||
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
|
||||
@@ -212,6 +216,7 @@ class TranslatorCacheTest extends TestCase
|
||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||
$translator->addResource('array', array('baz' => 'baz (b)'), 'b', 'messages+intl-icu');
|
||||
|
||||
$catalogue = $translator->getCatalogue('a');
|
||||
$this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message.
|
||||
@@ -230,12 +235,14 @@ class TranslatorCacheTest extends TestCase
|
||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||
$translator->addResource('array', array('foo' => 'foo (b)'), 'b');
|
||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||
$translator->addResource('array', array('baz' => 'baz (b)'), 'b', 'messages+intl-icu');
|
||||
|
||||
$catalogue = $translator->getCatalogue('a');
|
||||
$this->assertFalse($catalogue->defines('bar'));
|
||||
|
||||
$fallback = $catalogue->getFallbackCatalogue();
|
||||
$this->assertTrue($fallback->defines('foo'));
|
||||
$this->assertTrue($fallback->defines('baz', 'messages+intl-icu'));
|
||||
}
|
||||
|
||||
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
|
||||
|
@@ -234,6 +234,42 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals('bar', $translator->trans('foo', array(), 'resources'));
|
||||
}
|
||||
|
||||
public function testTransWithIcuFallbackLocale()
|
||||
{
|
||||
$translator = new Translator('en_GB');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en_GB');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en_001');
|
||||
$translator->addResource('array', array('baz' => 'foobaz'), 'en');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('foobar', $translator->trans('bar'));
|
||||
$this->assertSame('foobaz', $translator->trans('baz'));
|
||||
}
|
||||
|
||||
public function testTransWithIcuVariantFallbackLocale()
|
||||
{
|
||||
$translator = new Translator('en_GB_scouse');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en_GB_scouse');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en_GB');
|
||||
$translator->addResource('array', array('baz' => 'foobaz'), 'en_001');
|
||||
$translator->addResource('array', array('qux' => 'fooqux'), 'en');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('foobar', $translator->trans('bar'));
|
||||
$this->assertSame('foobaz', $translator->trans('baz'));
|
||||
$this->assertSame('fooqux', $translator->trans('qux'));
|
||||
}
|
||||
|
||||
public function testTransWithIcuRootFallbackLocale()
|
||||
{
|
||||
$translator = new Translator('az_Cyrl');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'az_Cyrl');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'az');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('bar', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
public function testTransWithFallbackLocaleBis()
|
||||
{
|
||||
$translator = new Translator('en_US');
|
||||
@@ -357,6 +393,7 @@ class TranslatorTest extends TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoice($expected, $id, $translation, $number, $parameters, $locale, $domain)
|
||||
{
|
||||
@@ -370,6 +407,7 @@ class TranslatorTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getInvalidLocalesTests
|
||||
* @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceInvalidLocale($locale)
|
||||
{
|
||||
@@ -382,6 +420,7 @@ class TranslatorTest extends TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider getValidLocalesTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceValidLocale($locale)
|
||||
{
|
||||
@@ -463,7 +502,7 @@ class TranslatorTest extends TestCase
|
||||
array('Il y a 0 pomme', new StringClass('{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples'), '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array(), 'fr', ''),
|
||||
|
||||
// Override %count% with a custom value
|
||||
array('Il y a quelques pommes', 'one: There is one apple|more: There are %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 2, array('%count%' => 'quelques'), 'fr', ''),
|
||||
array('Il y a quelques pommes', 'one: There is one apple|more: There are %count% apples', 'one: Il y a %count% pomme|more: Il y a quelques pommes', 2, array('%count%' => 'quelques'), 'fr', ''),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -501,6 +540,24 @@ class TranslatorTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
*/
|
||||
public function testIntlFormattedDomain()
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
|
||||
$translator->addResource('array', array('some_message' => 'Hello %name%'), 'en');
|
||||
$this->assertSame('Hello Bob', $translator->trans('some_message', array('%name%' => 'Bob')));
|
||||
|
||||
$translator->addResource('array', array('some_message' => 'Hi {name}'), 'en', 'messages+intl-icu');
|
||||
$this->assertSame('Hi Bob', $translator->trans('some_message', array('%name%' => 'Bob')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceFallback()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
@@ -511,6 +568,9 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceFallbackBis()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
@@ -521,6 +581,9 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTransChoiceFallbackWithNoTranslation()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
|
@@ -14,6 +14,9 @@
|
||||
<source>baz</source>
|
||||
<target>foo</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="4" resname="qux">
|
||||
<source>qux source</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
Reference in New Issue
Block a user