updated packages
This commit is contained in:
@@ -20,7 +20,7 @@ abstract class AbstractOperationTest extends TestCase
|
||||
public function testGetEmptyDomains()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
[],
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en'),
|
||||
new MessageCatalogue('en')
|
||||
@@ -31,10 +31,10 @@ abstract class AbstractOperationTest extends TestCase
|
||||
public function testGetMergedDomains()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array('a', 'b', 'c'),
|
||||
['a', 'b', 'c'],
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('a' => array(), 'b' => array())),
|
||||
new MessageCatalogue('en', array('b' => array(), 'c' => array()))
|
||||
new MessageCatalogue('en', ['a' => [], 'b' => []]),
|
||||
new MessageCatalogue('en', ['b' => [], 'c' => []])
|
||||
)->getDomains()
|
||||
);
|
||||
}
|
||||
@@ -51,9 +51,9 @@ abstract class AbstractOperationTest extends TestCase
|
||||
public function testGetEmptyMessages()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
[],
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('a' => array())),
|
||||
new MessageCatalogue('en', ['a' => []]),
|
||||
new MessageCatalogue('en')
|
||||
)->getMessages('a')
|
||||
);
|
||||
|
||||
@@ -20,22 +20,22 @@ class MergeOperationTest extends AbstractOperationTest
|
||||
public function testGetMessagesFromSingleDomain()
|
||||
{
|
||||
$operation = $this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))),
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'),
|
||||
['a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'],
|
||||
$operation->getMessages('messages')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('c' => 'new_c'),
|
||||
['c' => 'new_c'],
|
||||
$operation->getNewMessages('messages')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
[],
|
||||
$operation->getObsoleteMessages('messages')
|
||||
);
|
||||
}
|
||||
@@ -43,12 +43,12 @@ class MergeOperationTest extends AbstractOperationTest
|
||||
public function testGetResultFromSingleDomain()
|
||||
{
|
||||
$this->assertEquals(
|
||||
new MessageCatalogue('en', array(
|
||||
'messages' => array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'),
|
||||
)),
|
||||
new MessageCatalogue('en', [
|
||||
'messages' => ['a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'],
|
||||
]),
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))),
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
@@ -56,27 +56,27 @@ 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'),
|
||||
)),
|
||||
new MessageCatalogue('en', [
|
||||
'messages' => ['a' => 'old_a', 'b' => 'old_b'],
|
||||
'messages+intl-icu' => ['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')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b'], 'messages+intl-icu' => ['d' => 'old_d']]),
|
||||
new MessageCatalogue('en', ['messages+intl-icu' => ['a' => 'new_a', 'c' => 'new_c']])
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMetadata()
|
||||
{
|
||||
$leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b')));
|
||||
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]);
|
||||
$leftCatalogue->setMetadata('a', 'foo', 'messages');
|
||||
$leftCatalogue->setMetadata('b', 'bar', 'messages');
|
||||
$rightCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'new_b', 'c' => 'new_c')));
|
||||
$rightCatalogue = new MessageCatalogue('en', ['messages' => ['b' => 'new_b', 'c' => 'new_c']]);
|
||||
$rightCatalogue->setMetadata('b', 'baz', 'messages');
|
||||
$rightCatalogue->setMetadata('c', 'qux', 'messages');
|
||||
|
||||
$mergedCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c')));
|
||||
$mergedCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c']]);
|
||||
$mergedCatalogue->setMetadata('a', 'foo', 'messages');
|
||||
$mergedCatalogue->setMetadata('b', 'bar', 'messages');
|
||||
$mergedCatalogue->setMetadata('c', 'qux', 'messages');
|
||||
|
||||
@@ -20,22 +20,22 @@ class TargetOperationTest extends AbstractOperationTest
|
||||
public function testGetMessagesFromSingleDomain()
|
||||
{
|
||||
$operation = $this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))),
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('a' => 'old_a', 'c' => 'new_c'),
|
||||
['a' => 'old_a', 'c' => 'new_c'],
|
||||
$operation->getMessages('messages')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('c' => 'new_c'),
|
||||
['c' => 'new_c'],
|
||||
$operation->getNewMessages('messages')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('b' => 'old_b'),
|
||||
['b' => 'old_b'],
|
||||
$operation->getObsoleteMessages('messages')
|
||||
);
|
||||
}
|
||||
@@ -43,12 +43,12 @@ class TargetOperationTest extends AbstractOperationTest
|
||||
public function testGetResultFromSingleDomain()
|
||||
{
|
||||
$this->assertEquals(
|
||||
new MessageCatalogue('en', array(
|
||||
'messages' => array('a' => 'old_a', 'c' => 'new_c'),
|
||||
)),
|
||||
new MessageCatalogue('en', [
|
||||
'messages' => ['a' => 'old_a', 'c' => 'new_c'],
|
||||
]),
|
||||
$this->createOperation(
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))),
|
||||
new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
@@ -56,27 +56,27 @@ 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'),
|
||||
)),
|
||||
new MessageCatalogue('en', [
|
||||
'messages' => ['a' => 'old_a'],
|
||||
'messages+intl-icu' => ['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')))
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'old_a'], 'messages+intl-icu' => ['b' => 'old_b']]),
|
||||
new MessageCatalogue('en', ['messages' => ['a' => 'new_a'], 'messages+intl-icu' => ['c' => 'new_c']])
|
||||
)->getResult()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetResultWithMetadata()
|
||||
{
|
||||
$leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b')));
|
||||
$leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]);
|
||||
$leftCatalogue->setMetadata('a', 'foo', 'messages');
|
||||
$leftCatalogue->setMetadata('b', 'bar', 'messages');
|
||||
$rightCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'new_b', 'c' => 'new_c')));
|
||||
$rightCatalogue = new MessageCatalogue('en', ['messages' => ['b' => 'new_b', 'c' => 'new_c']]);
|
||||
$rightCatalogue->setMetadata('b', 'baz', 'messages');
|
||||
$rightCatalogue->setMetadata('c', 'qux', 'messages');
|
||||
|
||||
$diffCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'old_b', 'c' => 'new_c')));
|
||||
$diffCatalogue = new MessageCatalogue('en', ['messages' => ['b' => 'old_b', 'c' => 'new_c']]);
|
||||
$diffCatalogue->setMetadata('b', 'bar', 'messages');
|
||||
$diffCatalogue->setMetadata('c', 'qux', 'messages');
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ class XliffLintCommandTest extends TestCase
|
||||
$filename = $this->createFile();
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => $filename),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
['filename' => $filename],
|
||||
['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
|
||||
@@ -47,8 +47,8 @@ class XliffLintCommandTest extends TestCase
|
||||
$filename2 = $this->createFile();
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => array($filename1, $filename2)),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
['filename' => [$filename1, $filename2]],
|
||||
['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
|
||||
@@ -64,8 +64,8 @@ class XliffLintCommandTest extends TestCase
|
||||
$filename = $this->createFile('note', $targetLanguage, $fileNamePattern);
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => $filename),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
['filename' => $filename],
|
||||
['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals($mustFail ? 1 : 0, $tester->getStatusCode());
|
||||
@@ -77,7 +77,7 @@ class XliffLintCommandTest extends TestCase
|
||||
$tester = $this->createCommandTester();
|
||||
$filename = $this->createFile('note <target>');
|
||||
|
||||
$tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
$tester->execute(['filename' => $filename], ['decorated' => false]);
|
||||
|
||||
$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
|
||||
$this->assertContains('Opening and ending tag mismatch: target line 6 and source', trim($tester->getDisplay()));
|
||||
@@ -88,7 +88,7 @@ class XliffLintCommandTest extends TestCase
|
||||
$tester = $this->createCommandTester();
|
||||
$filename = $this->createFile('note', 'es');
|
||||
|
||||
$tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
$tester->execute(['filename' => $filename], ['decorated' => false]);
|
||||
|
||||
$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
|
||||
$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()));
|
||||
@@ -103,7 +103,7 @@ class XliffLintCommandTest extends TestCase
|
||||
$filename = $this->createFile();
|
||||
unlink($filename);
|
||||
|
||||
$tester->execute(array('filename' => $filename), array('decorated' => false));
|
||||
$tester->execute(['filename' => $filename], ['decorated' => false]);
|
||||
}
|
||||
|
||||
public function testGetHelp()
|
||||
@@ -179,7 +179,7 @@ XLIFF;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->files = array();
|
||||
$this->files = [];
|
||||
@mkdir(sys_get_temp_dir().'/translation-xliff-lint-test');
|
||||
}
|
||||
|
||||
@@ -195,13 +195,13 @@ XLIFF;
|
||||
|
||||
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);
|
||||
yield [false, 'messages.%locale%.xlf', 'en', false];
|
||||
yield [false, 'messages.%locale%.xlf', 'es', true];
|
||||
yield [false, '%locale%.messages.xlf', 'en', false];
|
||||
yield [false, '%locale%.messages.xlf', 'es', true];
|
||||
yield [true, 'messages.%locale%.xlf', 'en', false];
|
||||
yield [true, 'messages.%locale%.xlf', 'es', true];
|
||||
yield [true, '%locale%.messages.xlf', 'en', true];
|
||||
yield [true, '%locale%.messages.xlf', 'es', true];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class TranslationDataCollectorTest extends TestCase
|
||||
public function testCollectEmptyMessages()
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue(array()));
|
||||
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue([]));
|
||||
|
||||
$dataCollector = new TranslationDataCollector($translator);
|
||||
$dataCollector->lateCollect();
|
||||
@@ -35,94 +35,94 @@ class TranslationDataCollectorTest extends TestCase
|
||||
$this->assertEquals(0, $dataCollector->getCountMissings());
|
||||
$this->assertEquals(0, $dataCollector->getCountFallbacks());
|
||||
$this->assertEquals(0, $dataCollector->getCountDefines());
|
||||
$this->assertEquals(array(), $dataCollector->getMessages()->getValue());
|
||||
$this->assertEquals([], $dataCollector->getMessages()->getValue());
|
||||
}
|
||||
|
||||
public function testCollect()
|
||||
{
|
||||
$collectedMessages = array(
|
||||
array(
|
||||
$collectedMessages = [
|
||||
[
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'parameters' => ['%count%' => 3],
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 3),
|
||||
'parameters' => ['%count%' => 3],
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 4, '%foo%' => 'bar'),
|
||||
'parameters' => ['%count%' => 4, '%foo%' => 'bar'],
|
||||
'transChoiceNumber' => 4,
|
||||
),
|
||||
);
|
||||
$expectedMessages = array(
|
||||
array(
|
||||
],
|
||||
];
|
||||
$expectedMessages = [
|
||||
[
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'count' => 1,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'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'),
|
||||
),
|
||||
'parameters' => [
|
||||
['%count%' => 3],
|
||||
['%count%' => 3],
|
||||
['%count%' => 4, '%foo%' => 'bar'],
|
||||
],
|
||||
'transChoiceNumber' => 3,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$translator = $this->getTranslator();
|
||||
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages));
|
||||
|
||||
@@ -21,60 +21,60 @@ class DataCollectorTranslatorTest extends TestCase
|
||||
public function testCollectMessages()
|
||||
{
|
||||
$collector = $this->createCollector();
|
||||
$collector->setFallbackLocales(array('fr', 'ru'));
|
||||
$collector->setFallbackLocales(['fr', 'ru']);
|
||||
|
||||
$collector->trans('foo');
|
||||
$collector->trans('bar');
|
||||
$collector->trans('choice', array('%count%' => 0));
|
||||
$collector->trans('choice', ['%count%' => 0]);
|
||||
$collector->trans('bar_ru');
|
||||
$collector->trans('bar_ru', array('foo' => 'bar'));
|
||||
$collector->trans('bar_ru', ['foo' => 'bar']);
|
||||
|
||||
$expectedMessages = array();
|
||||
$expectedMessages[] = array(
|
||||
$expectedMessages = [];
|
||||
$expectedMessages[] = [
|
||||
'id' => 'foo',
|
||||
'translation' => 'foo (en)',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
];
|
||||
$expectedMessages[] = [
|
||||
'id' => 'bar',
|
||||
'translation' => 'bar (fr)',
|
||||
'locale' => 'fr',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
];
|
||||
$expectedMessages[] = [
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 0),
|
||||
'parameters' => ['%count%' => 0],
|
||||
'transChoiceNumber' => 0,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
];
|
||||
$expectedMessages[] = [
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array(),
|
||||
'parameters' => [],
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
$expectedMessages[] = array(
|
||||
];
|
||||
$expectedMessages[] = [
|
||||
'id' => 'bar_ru',
|
||||
'translation' => 'bar (ru)',
|
||||
'locale' => 'ru',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
|
||||
'parameters' => array('foo' => 'bar'),
|
||||
'parameters' => ['foo' => 'bar'],
|
||||
'transChoiceNumber' => null,
|
||||
);
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedMessages, $collector->getCollectedMessages());
|
||||
}
|
||||
@@ -85,20 +85,20 @@ class DataCollectorTranslatorTest extends TestCase
|
||||
public function testCollectMessagesTransChoice()
|
||||
{
|
||||
$collector = $this->createCollector();
|
||||
$collector->setFallbackLocales(array('fr', 'ru'));
|
||||
$collector->setFallbackLocales(['fr', 'ru']);
|
||||
$collector->transChoice('choice', 0);
|
||||
|
||||
$expectedMessages = array();
|
||||
$expectedMessages = [];
|
||||
|
||||
$expectedMessages[] = array(
|
||||
$expectedMessages[] = [
|
||||
'id' => 'choice',
|
||||
'translation' => 'choice',
|
||||
'locale' => 'en',
|
||||
'domain' => 'messages',
|
||||
'state' => DataCollectorTranslator::MESSAGE_MISSING,
|
||||
'parameters' => array('%count%' => 0),
|
||||
'parameters' => ['%count%' => 0],
|
||||
'transChoiceNumber' => 0,
|
||||
);
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedMessages, $collector->getCollectedMessages());
|
||||
}
|
||||
@@ -107,9 +107,9 @@ class DataCollectorTranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (en)'), 'en');
|
||||
$translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
|
||||
$translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru');
|
||||
$translator->addResource('array', ['foo' => 'foo (en)'], 'en');
|
||||
$translator->addResource('array', ['bar' => 'bar (fr)'], 'fr');
|
||||
$translator->addResource('array', ['bar_ru' => 'bar (ru)'], 'ru');
|
||||
|
||||
return new DataCollectorTranslator($translator);
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ class TranslationDumperPassTest extends TestCase
|
||||
$container = new ContainerBuilder();
|
||||
$writerDefinition = $container->register('translation.writer');
|
||||
$container->register('foo.id')
|
||||
->addTag('translation.dumper', array('alias' => 'bar.alias'));
|
||||
->addTag('translation.dumper', ['alias' => 'bar.alias']);
|
||||
|
||||
$translationDumperPass = new TranslationDumperPass();
|
||||
$translationDumperPass->process($container);
|
||||
|
||||
$this->assertEquals(array(array('addDumper', array('bar.alias', new Reference('foo.id')))), $writerDefinition->getMethodCalls());
|
||||
$this->assertEquals([['addDumper', ['bar.alias', new Reference('foo.id')]]], $writerDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessNoDefinitionFound()
|
||||
|
||||
@@ -23,12 +23,12 @@ class TranslationExtractorPassTest extends TestCase
|
||||
$container = new ContainerBuilder();
|
||||
$extractorDefinition = $container->register('translation.extractor');
|
||||
$container->register('foo.id')
|
||||
->addTag('translation.extractor', array('alias' => 'bar.alias'));
|
||||
->addTag('translation.extractor', ['alias' => 'bar.alias']);
|
||||
|
||||
$translationDumperPass = new TranslationExtractorPass();
|
||||
$translationDumperPass->process($container);
|
||||
|
||||
$this->assertEquals(array(array('addExtractor', array('bar.alias', new Reference('foo.id')))), $extractorDefinition->getMethodCalls());
|
||||
$this->assertEquals([['addExtractor', ['bar.alias', new Reference('foo.id')]]], $extractorDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
public function testProcessNoDefinitionFound()
|
||||
@@ -56,7 +56,7 @@ class TranslationExtractorPassTest extends TestCase
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('translation.extractor');
|
||||
$container->register('foo.id')
|
||||
->addTag('translation.extractor', array());
|
||||
->addTag('translation.extractor', []);
|
||||
|
||||
$definition->expects($this->never())->method('addMethodCall');
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ class TranslationPassTest extends TestCase
|
||||
public function testValidCollector()
|
||||
{
|
||||
$loader = (new Definition())
|
||||
->addTag('translation.loader', array('alias' => 'xliff', 'legacy-alias' => 'xlf'));
|
||||
->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf']);
|
||||
|
||||
$reader = new Definition();
|
||||
|
||||
$translator = (new Definition())
|
||||
->setArguments(array(null, null, null, null));
|
||||
->setArguments([null, null, null, null]);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('translator.default', $translator);
|
||||
@@ -39,19 +39,19 @@ class TranslationPassTest extends TestCase
|
||||
$pass->process($container);
|
||||
|
||||
$expectedReader = (new Definition())
|
||||
->addMethodCall('addLoader', array('xliff', new Reference('translation.xliff_loader')))
|
||||
->addMethodCall('addLoader', array('xlf', new Reference('translation.xliff_loader')))
|
||||
->addMethodCall('addLoader', ['xliff', new Reference('translation.xliff_loader')])
|
||||
->addMethodCall('addLoader', ['xlf', new Reference('translation.xliff_loader')])
|
||||
;
|
||||
$this->assertEquals($expectedReader, $reader);
|
||||
|
||||
$expectedLoader = (new Definition())
|
||||
->addTag('translation.loader', array('alias' => 'xliff', 'legacy-alias' => 'xlf'))
|
||||
->addTag('translation.loader', ['alias' => 'xliff', 'legacy-alias' => 'xlf'])
|
||||
;
|
||||
$this->assertEquals($expectedLoader, $loader);
|
||||
|
||||
$this->assertSame(array('translation.xliff_loader' => array('xliff', 'xlf')), $translator->getArgument(3));
|
||||
$this->assertSame(['translation.xliff_loader' => ['xliff', 'xlf']], $translator->getArgument(3));
|
||||
|
||||
$expected = array('translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader')));
|
||||
$expected = ['translation.xliff_loader' => new ServiceClosureArgument(new Reference('translation.xliff_loader'))];
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ class CsvFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar', 'bar' => 'foo
|
||||
foo', 'foo;foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar', 'bar' => 'foo
|
||||
foo', 'foo;foo' => 'bar']);
|
||||
|
||||
$dumper = new CsvFileDumper();
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ class FileDumperTest extends TestCase
|
||||
$tempDir = sys_get_temp_dir();
|
||||
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new ConcreteFileDumper();
|
||||
$dumper->dump($catalogue, array('path' => $tempDir));
|
||||
$dumper->dump($catalogue, ['path' => $tempDir]);
|
||||
|
||||
$this->assertFileExists($tempDir.'/messages.en.concrete');
|
||||
|
||||
@@ -37,13 +37,13 @@ class FileDumperTest extends TestCase
|
||||
$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');
|
||||
$catalogue->add(['foo' => 'bar'], 'd1');
|
||||
$catalogue->add(['bar' => 'foo'], 'd1+intl-icu');
|
||||
$catalogue->add(['bar' => 'foo'], 'd2+intl-icu');
|
||||
|
||||
$dumper = new ConcreteFileDumper();
|
||||
@unlink($tempDir.'/d2.en.concrete');
|
||||
$dumper->dump($catalogue, array('path' => $tempDir));
|
||||
$dumper->dump($catalogue, ['path' => $tempDir]);
|
||||
|
||||
$this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar');
|
||||
@unlink($tempDir.'/d1.en.concrete');
|
||||
@@ -63,11 +63,11 @@ class FileDumperTest extends TestCase
|
||||
$file = $translationsDir.'/messages.en.concrete';
|
||||
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new ConcreteFileDumper();
|
||||
$dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
|
||||
$dumper->dump($catalogue, array('path' => $tempDir));
|
||||
$dumper->dump($catalogue, ['path' => $tempDir]);
|
||||
|
||||
$this->assertFileExists($file);
|
||||
|
||||
@@ -78,7 +78,7 @@ class FileDumperTest extends TestCase
|
||||
|
||||
class ConcreteFileDumper extends FileDumper
|
||||
{
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
{
|
||||
return http_build_query($messages->all($domain), '', '&');
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class IcuResFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new IcuResFileDumper();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class IniFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new IniFileDumper();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class JsonFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new JsonFileDumper();
|
||||
|
||||
@@ -30,10 +30,10 @@ class JsonFileDumperTest extends TestCase
|
||||
public function testDumpWithCustomEncoding()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => '"bar"'));
|
||||
$catalogue->add(['foo' => '"bar"']);
|
||||
|
||||
$dumper = new JsonFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', array('json_encoding' => JSON_HEX_QUOT)));
|
||||
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', ['json_encoding' => JSON_HEX_QUOT]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class MoFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new MoFileDumper();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class PhpFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new PhpFileDumper();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class PoFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar', 'bar' => 'foo']);
|
||||
|
||||
$dumper = new PoFileDumper();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class QtFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(array('foo' => 'bar'), 'resources');
|
||||
$catalogue->add(['foo' => 'bar'], 'resources');
|
||||
|
||||
$dumper = new QtFileDumper();
|
||||
|
||||
|
||||
@@ -20,49 +20,64 @@ class XliffFileDumperTest extends TestCase
|
||||
public function testFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array(
|
||||
$catalogue->add([
|
||||
'foo' => 'bar',
|
||||
'key' => '',
|
||||
'key.with.cdata' => '<source> & <target>',
|
||||
));
|
||||
$catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz'))));
|
||||
$catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux'))));
|
||||
]);
|
||||
$catalogue->setMetadata('foo', ['notes' => [['priority' => 1, 'from' => 'bar', 'content' => 'baz']]]);
|
||||
$catalogue->setMetadata('key', ['notes' => [['content' => 'baz'], ['content' => 'qux']]]);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__.'/../fixtures/resources-clean.xlf',
|
||||
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
|
||||
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatCatalogueXliff2()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array(
|
||||
$catalogue->add([
|
||||
'foo' => 'bar',
|
||||
'key' => '',
|
||||
'key.with.cdata' => '<source> & <target>',
|
||||
));
|
||||
$catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
|
||||
]);
|
||||
$catalogue->setMetadata('key', ['target-attributes' => ['order' => 1]]);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__.'/../fixtures/resources-2.0-clean.xlf',
|
||||
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
|
||||
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatIcuCatalogueXliff2()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add([
|
||||
'foo' => 'bar',
|
||||
], 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__.'/../fixtures/resources-2.0+intl-icu.xlf',
|
||||
$dumper->formatCatalogue($catalogue, 'messages'.MessageCatalogue::INTL_DOMAIN_SUFFIX, ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatCatalogueWithCustomToolInfo()
|
||||
{
|
||||
$options = array(
|
||||
$options = [
|
||||
'default_locale' => 'en_US',
|
||||
'tool_info' => array('tool-id' => 'foo', 'tool-name' => 'foo', 'tool-version' => '0.0', 'tool-company' => 'Foo'),
|
||||
);
|
||||
'tool_info' => ['tool-id' => 'foo', 'tool-name' => 'foo', 'tool-version' => '0.0', 'tool-company' => 'Foo'],
|
||||
];
|
||||
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array('foo' => 'bar'));
|
||||
$catalogue->add(['foo' => 'bar']);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
@@ -75,41 +90,41 @@ class XliffFileDumperTest extends TestCase
|
||||
public function testFormatCatalogueWithTargetAttributesMetadata()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array(
|
||||
$catalogue->add([
|
||||
'foo' => 'bar',
|
||||
));
|
||||
$catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
|
||||
]);
|
||||
$catalogue->setMetadata('foo', ['target-attributes' => ['state' => 'needs-translation']]);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__.'/../fixtures/resources-target-attributes.xlf',
|
||||
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR'))
|
||||
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatCatalogueWithNotesMetadata()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array(
|
||||
$catalogue->add([
|
||||
'foo' => 'bar',
|
||||
'baz' => 'biz',
|
||||
));
|
||||
$catalogue->setMetadata('foo', array('notes' => array(
|
||||
array('category' => 'state', 'content' => 'new'),
|
||||
array('category' => 'approved', 'content' => 'true'),
|
||||
array('category' => 'section', 'content' => 'user login', 'priority' => '1'),
|
||||
)));
|
||||
$catalogue->setMetadata('baz', array('notes' => array(
|
||||
array('id' => 'x', 'content' => 'x_content'),
|
||||
array('appliesTo' => 'target', 'category' => 'quality', 'content' => 'Fuzzy'),
|
||||
)));
|
||||
]);
|
||||
$catalogue->setMetadata('foo', ['notes' => [
|
||||
['category' => 'state', 'content' => 'new'],
|
||||
['category' => 'approved', 'content' => 'true'],
|
||||
['category' => 'section', 'content' => 'user login', 'priority' => '1'],
|
||||
]]);
|
||||
$catalogue->setMetadata('baz', ['notes' => [
|
||||
['id' => 'x', 'content' => 'x_content'],
|
||||
['appliesTo' => 'target', 'category' => 'quality', 'content' => 'Fuzzy'],
|
||||
]]);
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
__DIR__.'/../fixtures/resources-notes-meta.xlf',
|
||||
$dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR', 'xliff_version' => '2.0'))
|
||||
$dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'fr_FR', 'xliff_version' => '2.0'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,25 +20,23 @@ class YamlFileDumperTest extends TestCase
|
||||
public function testTreeFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(
|
||||
array(
|
||||
'foo.bar1' => 'value1',
|
||||
'foo.bar2' => 'value2',
|
||||
));
|
||||
$catalogue->add([
|
||||
'foo.bar1' => 'value1',
|
||||
'foo.bar2' => 'value2',
|
||||
]);
|
||||
|
||||
$dumper = new YamlFileDumper();
|
||||
|
||||
$this->assertStringEqualsFile(__DIR__.'/../fixtures/messages.yml', $dumper->formatCatalogue($catalogue, 'messages', array('as_tree' => true, 'inline' => 999)));
|
||||
$this->assertStringEqualsFile(__DIR__.'/../fixtures/messages.yml', $dumper->formatCatalogue($catalogue, 'messages', ['as_tree' => true, 'inline' => 999]));
|
||||
}
|
||||
|
||||
public function testLinearFormatCatalogue()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->add(
|
||||
array(
|
||||
'foo.bar1' => 'value1',
|
||||
'foo.bar2' => 'value2',
|
||||
));
|
||||
$catalogue->add([
|
||||
'foo.bar1' => 'value1',
|
||||
'foo.bar2' => 'value2',
|
||||
]);
|
||||
|
||||
$dumper = new YamlFileDumper();
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ EOF;
|
||||
nowdoc key with whitespace and nonescaped \$\n sequences
|
||||
EOF;
|
||||
// Assert
|
||||
$expectedCatalogue = array(
|
||||
'messages' => array(
|
||||
$expectedCatalogue = [
|
||||
'messages' => [
|
||||
'single-quoted key' => 'prefixsingle-quoted key',
|
||||
'double-quoted key' => 'prefixdouble-quoted key',
|
||||
'heredoc key' => 'prefixheredoc key',
|
||||
@@ -51,8 +51,10 @@ EOF;
|
||||
$expectedHeredoc => 'prefix'.$expectedHeredoc,
|
||||
$expectedNowdoc => 'prefix'.$expectedNowdoc,
|
||||
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
|
||||
),
|
||||
'not_messages' => array(
|
||||
'concatenated message with heredoc and nowdoc' => 'prefixconcatenated message with heredoc and nowdoc',
|
||||
'default domain' => 'prefixdefault domain',
|
||||
],
|
||||
'not_messages' => [
|
||||
'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array',
|
||||
'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array',
|
||||
'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array',
|
||||
@@ -62,8 +64,8 @@ EOF;
|
||||
'typecast' => 'prefixtypecast',
|
||||
'msg1' => 'prefixmsg1',
|
||||
'msg2' => 'prefixmsg2',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$actualCatalogue = $catalogue->all();
|
||||
|
||||
$this->assertEquals($expectedCatalogue, $actualCatalogue);
|
||||
@@ -72,7 +74,7 @@ EOF;
|
||||
public function resourcesProvider()
|
||||
{
|
||||
$directory = __DIR__.'/../fixtures/extractor/';
|
||||
$splFiles = array();
|
||||
$splFiles = [];
|
||||
foreach (new \DirectoryIterator($directory) as $fileInfo) {
|
||||
if ($fileInfo->isDot()) {
|
||||
continue;
|
||||
@@ -83,13 +85,13 @@ EOF;
|
||||
$splFiles[] = $fileInfo->getFileInfo();
|
||||
}
|
||||
|
||||
return array(
|
||||
array($directory),
|
||||
array($phpFile),
|
||||
array(glob($directory.'*')),
|
||||
array($splFiles),
|
||||
array(new \ArrayObject(glob($directory.'*'))),
|
||||
array(new \ArrayObject($splFiles)),
|
||||
);
|
||||
return [
|
||||
[$directory],
|
||||
[$phpFile],
|
||||
[glob($directory.'*')],
|
||||
[$splFiles],
|
||||
[new \ArrayObject(glob($directory.'*'))],
|
||||
[new \ArrayObject($splFiles)],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class IntlFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
public function testInvalidFormat()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
(new IntlFormatter())->formatIntl('{foo', 'en', array(2));
|
||||
(new IntlFormatter())->formatIntl('{foo', 'en', [2]);
|
||||
}
|
||||
|
||||
public function testFormatWithNamedArguments()
|
||||
@@ -59,38 +59,38 @@ class IntlFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
other {{host} invites {guest} as one of the # people invited to their party.}}}}
|
||||
_MSG_;
|
||||
|
||||
$message = (new IntlFormatter())->formatIntl($chooseMessage, 'en', array(
|
||||
$message = (new IntlFormatter())->formatIntl($chooseMessage, 'en', [
|
||||
'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(
|
||||
return [
|
||||
[
|
||||
'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),
|
||||
),
|
||||
);
|
||||
[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')));
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', ['name' => 'Fab']));
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', ['%name%' => 'Fab']));
|
||||
$this->assertSame('Hello Fab', $formatter->formatIntl('Hello {name}', 'en', ['{{ name }}' => 'Fab']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class MessageFormatterTest extends TestCase
|
||||
/**
|
||||
* @dataProvider getTransMessages
|
||||
*/
|
||||
public function testFormat($expected, $message, $parameters = array())
|
||||
public function testFormat($expected, $message, $parameters = [])
|
||||
{
|
||||
$this->assertEquals($expected, $this->getMessageFormatter()->format($message, 'en', $parameters));
|
||||
}
|
||||
@@ -35,45 +35,45 @@ class MessageFormatterTest extends TestCase
|
||||
|
||||
public function getTransMessages()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'There is one apple',
|
||||
'There is one apple',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'There are 5 apples',
|
||||
'There are %count% apples',
|
||||
array('%count%' => 5),
|
||||
),
|
||||
array(
|
||||
['%count%' => 5],
|
||||
],
|
||||
[
|
||||
'There are 5 apples',
|
||||
'There are {{count}} apples',
|
||||
array('{{count}}' => 5),
|
||||
),
|
||||
);
|
||||
['{{count}}' => 5],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransChoiceMessages()
|
||||
{
|
||||
return array(
|
||||
array('Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0)),
|
||||
array('Il y a 1 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 1, array('%count%' => 1)),
|
||||
array('Il y a 10 pommes', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 10, array('%count%' => 10)),
|
||||
return [
|
||||
['Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, ['%count%' => 0]],
|
||||
['Il y a 1 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 1, ['%count%' => 1]],
|
||||
['Il y a 10 pommes', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 10, ['%count%' => 10]],
|
||||
|
||||
array('Il y a 0 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 0, array('%count%' => 0)),
|
||||
array('Il y a 1 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 1, array('%count%' => 1)),
|
||||
array('Il y a 10 pommes', 'Il y a %count% pomme|Il y a %count% pommes', 10, array('%count%' => 10)),
|
||||
['Il y a 0 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 0, ['%count%' => 0]],
|
||||
['Il y a 1 pomme', 'Il y a %count% pomme|Il y a %count% pommes', 1, ['%count%' => 1]],
|
||||
['Il y a 10 pommes', 'Il y a %count% pomme|Il y a %count% pommes', 10, ['%count%' => 10]],
|
||||
|
||||
array('Il y a 0 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0)),
|
||||
array('Il y a 1 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1)),
|
||||
array('Il y a 10 pommes', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10)),
|
||||
['Il y a 0 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, ['%count%' => 0]],
|
||||
['Il y a 1 pomme', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, ['%count%' => 1]],
|
||||
['Il y a 10 pommes', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, ['%count%' => 10]],
|
||||
|
||||
array('Il n\'y a aucune pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0)),
|
||||
array('Il y a 1 pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1)),
|
||||
array('Il y a 10 pommes', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10)),
|
||||
['Il n\'y a aucune pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, ['%count%' => 0]],
|
||||
['Il y a 1 pomme', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, ['%count%' => 1]],
|
||||
['Il y a 10 pommes', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, ['%count%' => 10]],
|
||||
|
||||
array('Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0)),
|
||||
);
|
||||
['Il y a 0 pomme', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, ['%count%' => 0]],
|
||||
];
|
||||
}
|
||||
|
||||
private function getMessageFormatter()
|
||||
|
||||
@@ -37,16 +37,16 @@ class IntervalTest extends TestCase
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array(true, 3, '{1,2, 3 ,4}'),
|
||||
array(false, 10, '{1,2, 3 ,4}'),
|
||||
array(false, 3, '[1,2]'),
|
||||
array(true, 1, '[1,2]'),
|
||||
array(true, 2, '[1,2]'),
|
||||
array(false, 1, ']1,2['),
|
||||
array(false, 2, ']1,2['),
|
||||
array(true, log(0), '[-Inf,2['),
|
||||
array(true, -log(0), '[-2,+Inf]'),
|
||||
);
|
||||
return [
|
||||
[true, 3, '{1,2, 3 ,4}'],
|
||||
[false, 10, '{1,2, 3 ,4}'],
|
||||
[false, 3, '[1,2]'],
|
||||
[true, 1, '[1,2]'],
|
||||
[true, 2, '[1,2]'],
|
||||
[false, 1, ']1,2['],
|
||||
[false, 2, ']1,2['],
|
||||
[true, log(0), '[-Inf,2['],
|
||||
[true, -log(0), '[-2,+Inf]'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ class CsvFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.csv';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
@@ -34,9 +34,9 @@ class CsvFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty.csv';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,9 +37,9 @@ class IcuDatFileLoaderTest extends LocalizedTestCase
|
||||
$resource = __DIR__.'/../fixtures/resourcebundle/dat/resources';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('symfony' => 'Symfony 2 is great'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['symfony' => 'Symfony 2 is great'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource.'.dat')], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testDatFrenchLoad()
|
||||
@@ -48,9 +48,9 @@ class IcuDatFileLoaderTest extends LocalizedTestCase
|
||||
$resource = __DIR__.'/../fixtures/resourcebundle/dat/resources';
|
||||
$catalogue = $loader->load($resource, 'fr', 'domain1');
|
||||
|
||||
$this->assertEquals(array('symfony' => 'Symfony 2 est génial'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['symfony' => 'Symfony 2 est génial'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('fr', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource.'.dat')], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,9 +26,9 @@ class IcuResFileLoaderTest extends LocalizedTestCase
|
||||
$resource = __DIR__.'/../fixtures/resourcebundle/res';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new DirectoryResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new DirectoryResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,9 @@ class IniFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.ini';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
@@ -34,9 +34,9 @@ class IniFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty.ini';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,9 @@ class JsonFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.json';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
@@ -34,9 +34,9 @@ class JsonFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty.json';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,9 @@ class MoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.mo';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadPlurals()
|
||||
@@ -34,9 +34,9 @@ class MoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/plurals.mo';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar', 'foos' => '{0} bar|{1} bars'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,8 +65,8 @@ class MoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty-translation.mo';
|
||||
$catalogue = $loader->load($resource, 'en', 'message');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('message'));
|
||||
$this->assertEquals([], $catalogue->all('message'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ class PhpFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.php';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,9 +23,9 @@ class PoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar', 'bar' => 'foo'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadPlurals()
|
||||
@@ -34,9 +34,9 @@ class PoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/plurals.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar', 'foos' => 'bar|bars'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar', 'foos' => 'bar|bars'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
@@ -45,9 +45,9 @@ class PoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,9 +66,9 @@ class PoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty-translation.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => ''), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => ''], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testEscapedId()
|
||||
|
||||
@@ -23,9 +23,9 @@ class QtFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.ts';
|
||||
$catalogue = $loader->load($resource, 'en', 'resources');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('resources'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('resources'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,8 +24,8 @@ class XliffFileLoaderTest extends TestCase
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
$this->assertSame([], libxml_get_errors());
|
||||
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ class XliffFileLoaderTest extends TestCase
|
||||
{
|
||||
$internalErrors = libxml_use_internal_errors(true);
|
||||
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
$this->assertSame([], libxml_get_errors());
|
||||
|
||||
$loader = new XliffFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/resources.xlf';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
$this->assertSame([], libxml_get_errors());
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
@@ -58,7 +58,7 @@ class XliffFileLoaderTest extends TestCase
|
||||
libxml_disable_entity_loader($disableEntities);
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadWithResname()
|
||||
@@ -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', 'qux' => 'qux source'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'], $catalogue->all('domain1'));
|
||||
}
|
||||
|
||||
public function testIncompleteResource()
|
||||
@@ -74,7 +74,7 @@ class XliffFileLoaderTest extends TestCase
|
||||
$loader = new XliffFileLoader();
|
||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'], $catalogue->all('domain1'));
|
||||
}
|
||||
|
||||
public function testEncoding()
|
||||
@@ -84,7 +84,7 @@ class XliffFileLoaderTest extends TestCase
|
||||
|
||||
$this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
|
||||
$this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz'))), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
|
||||
$this->assertEquals(['notes' => [['content' => utf8_decode('bäz')]], 'id' => '1'], $catalogue->getMetadata('foo', 'domain1'));
|
||||
}
|
||||
|
||||
public function testTargetAttributesAreStoredCorrectly()
|
||||
@@ -164,11 +164,11 @@ class XliffFileLoaderTest extends TestCase
|
||||
$loader = new XliffFileLoader();
|
||||
$catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo')), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
|
||||
$this->assertEquals(['notes' => [['priority' => 1, 'content' => 'foo']], 'id' => '1'], $catalogue->getMetadata('foo', 'domain1'));
|
||||
// message without target
|
||||
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo')), 'id' => '2'), $catalogue->getMetadata('extra', 'domain1'));
|
||||
$this->assertEquals(['notes' => [['content' => 'bar', 'from' => 'foo']], 'id' => '2'], $catalogue->getMetadata('extra', 'domain1'));
|
||||
// message with empty target
|
||||
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux')), 'id' => '123'), $catalogue->getMetadata('key', 'domain1'));
|
||||
$this->assertEquals(['notes' => [['content' => 'baz'], ['priority' => 2, 'from' => 'bar', 'content' => 'qux']], 'id' => '123'], $catalogue->getMetadata('key', 'domain1'));
|
||||
}
|
||||
|
||||
public function testLoadVersion2()
|
||||
@@ -178,15 +178,15 @@ class XliffFileLoaderTest extends TestCase
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
$this->assertSame([], libxml_get_errors());
|
||||
|
||||
$domains = $catalogue->all();
|
||||
$this->assertCount(3, $domains['domain1']);
|
||||
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||
|
||||
// target attributes
|
||||
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
|
||||
$this->assertEquals(['target-attributes' => ['order' => 1]], $catalogue->getMetadata('bar', 'domain1'));
|
||||
}
|
||||
|
||||
public function testLoadVersion2WithNoteMeta()
|
||||
@@ -196,8 +196,8 @@ class XliffFileLoaderTest extends TestCase
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
$this->assertSame([], libxml_get_errors());
|
||||
|
||||
// test for "foo" metadata
|
||||
$this->assertTrue($catalogue->defines('foo', 'domain1'));
|
||||
@@ -236,7 +236,7 @@ class XliffFileLoaderTest extends TestCase
|
||||
$catalog = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertSame('en', $catalog->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalog->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalog->getResources());
|
||||
$this->assertFalse(libxml_get_last_error());
|
||||
|
||||
// test for "foo" metadata
|
||||
|
||||
@@ -23,9 +23,9 @@ class YamlFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/resources.yml';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
@@ -34,9 +34,9 @@ class YamlFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/empty.yml';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(array(), $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,11 +43,11 @@ class LoggingTranslatorTest extends TestCase
|
||||
;
|
||||
|
||||
$translator = new Translator('ar');
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
|
||||
$translator->addResource('array', ['some_message2' => 'one thing|%count% things'], 'en');
|
||||
$loggableTranslator = new LoggingTranslator($translator, $logger);
|
||||
$loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
|
||||
$loggableTranslator->transChoice('some_message2', 10, ['%count%' => 10]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,6 +63,6 @@ class LoggingTranslatorTest extends TestCase
|
||||
|
||||
$translator = new Translator('ar');
|
||||
$loggableTranslator = new LoggingTranslator($translator, $logger);
|
||||
$loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
|
||||
$loggableTranslator->transChoice('some_message2', 10, ['%count%' => 10]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,40 +25,40 @@ class MessageCatalogueTest extends TestCase
|
||||
|
||||
public function testGetDomains()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array(), 'domain2' => array(), 'domain2+intl-icu' => array(), 'domain3+intl-icu' => array()));
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => [], 'domain2' => [], 'domain2+intl-icu' => [], 'domain3+intl-icu' => []]);
|
||||
|
||||
$this->assertEquals(array('domain1', 'domain2', 'domain3'), $catalogue->getDomains());
|
||||
$this->assertEquals(['domain1', 'domain2', 'domain3'], $catalogue->getDomains());
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', $messages = array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', $messages = ['domain1' => ['foo' => 'foo'], 'domain2' => ['bar' => 'bar']]);
|
||||
|
||||
$this->assertEquals(array('foo' => 'foo'), $catalogue->all('domain1'));
|
||||
$this->assertEquals(array(), $catalogue->all('domain88'));
|
||||
$this->assertEquals(['foo' => 'foo'], $catalogue->all('domain1'));
|
||||
$this->assertEquals([], $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'),
|
||||
);
|
||||
$messages = ['domain1+intl-icu' => ['foo' => 'bar']] + $messages + [
|
||||
'domain2+intl-icu' => ['bar' => 'foo'],
|
||||
'domain3+intl-icu' => ['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'));
|
||||
$this->assertEquals(['foo' => 'bar'], $catalogue->all('domain1'));
|
||||
$this->assertEquals(['bar' => 'foo'], $catalogue->all('domain2'));
|
||||
$this->assertEquals(['biz' => 'biz'], $catalogue->all('domain3'));
|
||||
|
||||
$messages = array(
|
||||
'domain1' => array('foo' => 'bar'),
|
||||
'domain2' => array('bar' => 'foo'),
|
||||
'domain3' => array('biz' => 'biz'),
|
||||
);
|
||||
$messages = [
|
||||
'domain1' => ['foo' => 'bar'],
|
||||
'domain2' => ['bar' => 'foo'],
|
||||
'domain3' => ['biz' => 'biz'],
|
||||
];
|
||||
$this->assertEquals($messages, $catalogue->all());
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2+intl-icu' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain2+intl-icu' => ['bar' => 'bar']]);
|
||||
|
||||
$this->assertTrue($catalogue->has('foo', 'domain1'));
|
||||
$this->assertTrue($catalogue->has('bar', 'domain2'));
|
||||
@@ -68,7 +68,7 @@ class MessageCatalogueTest extends TestCase
|
||||
|
||||
public function testGetSet()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'), 'domain2+intl-icu' => array('bar' => 'foo')));
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain2' => ['bar' => 'bar'], 'domain2+intl-icu' => ['bar' => 'foo']]);
|
||||
$catalogue->set('foo1', 'foo1', 'domain1');
|
||||
|
||||
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
|
||||
@@ -78,24 +78,24 @@ class MessageCatalogueTest extends TestCase
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue->add(array('foo1' => 'foo1'), 'domain1');
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain2' => ['bar' => 'bar']]);
|
||||
$catalogue->add(['foo1' => 'foo1'], 'domain1');
|
||||
|
||||
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
|
||||
|
||||
$catalogue->add(array('foo' => 'bar'), 'domain1');
|
||||
$catalogue->add(['foo' => 'bar'], 'domain1');
|
||||
$this->assertEquals('bar', $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
|
||||
|
||||
$catalogue->add(array('foo' => 'bar'), 'domain88');
|
||||
$catalogue->add(['foo' => 'bar'], 'domain88');
|
||||
$this->assertEquals('bar', $catalogue->get('foo', 'domain88'));
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain1+intl-icu' => array('bar' => 'bar')));
|
||||
$catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1');
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo'], 'domain1+intl-icu' => ['bar' => 'bar']]);
|
||||
$catalogue->replace($messages = ['foo1' => 'foo1'], 'domain1');
|
||||
|
||||
$this->assertEquals($messages, $catalogue->all('domain1'));
|
||||
}
|
||||
@@ -108,10 +108,10 @@ 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')));
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo']]);
|
||||
$catalogue->addResource($r);
|
||||
|
||||
$catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo1' => 'foo1'), 'domain2+intl-icu' => array('bar' => 'bar')));
|
||||
$catalogue1 = new MessageCatalogue('en', ['domain1' => ['foo1' => 'foo1'], 'domain2+intl-icu' => ['bar' => 'bar']]);
|
||||
$catalogue1->addResource($r1);
|
||||
|
||||
$catalogue->addCatalogue($catalogue1);
|
||||
@@ -121,7 +121,7 @@ class MessageCatalogueTest extends TestCase
|
||||
$this->assertEquals('bar', $catalogue->get('bar', 'domain2'));
|
||||
$this->assertEquals('bar', $catalogue->get('bar', 'domain2+intl-icu'));
|
||||
|
||||
$this->assertEquals(array($r, $r1), $catalogue->getResources());
|
||||
$this->assertEquals([$r, $r1], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testAddFallbackCatalogue()
|
||||
@@ -135,10 +135,10 @@ class MessageCatalogueTest extends TestCase
|
||||
$r2 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
|
||||
$r2->expects($this->any())->method('__toString')->will($this->returnValue('r2'));
|
||||
|
||||
$catalogue = new MessageCatalogue('fr_FR', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
|
||||
$catalogue = new MessageCatalogue('fr_FR', ['domain1' => ['foo' => 'foo'], 'domain2' => ['bar' => 'bar']]);
|
||||
$catalogue->addResource($r);
|
||||
|
||||
$catalogue1 = new MessageCatalogue('fr', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1')));
|
||||
$catalogue1 = new MessageCatalogue('fr', ['domain1' => ['foo' => 'bar', 'foo1' => 'foo1']]);
|
||||
$catalogue1->addResource($r1);
|
||||
|
||||
$catalogue2 = new MessageCatalogue('en');
|
||||
@@ -150,7 +150,7 @@ class MessageCatalogueTest extends TestCase
|
||||
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
|
||||
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
|
||||
|
||||
$this->assertEquals(array($r, $r1, $r2), $catalogue->getResources());
|
||||
$this->assertEquals([$r, $r1, $r2], $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ class MessageCatalogueTest extends TestCase
|
||||
public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$catalogue->addCatalogue(new MessageCatalogue('fr', array()));
|
||||
$catalogue->addCatalogue(new MessageCatalogue('fr', []));
|
||||
}
|
||||
|
||||
public function testGetAddResource()
|
||||
@@ -199,13 +199,13 @@ class MessageCatalogueTest extends TestCase
|
||||
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
|
||||
$catalogue->addResource($r1);
|
||||
|
||||
$this->assertEquals(array($r, $r1), $catalogue->getResources());
|
||||
$this->assertEquals([$r, $r1], $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testMetadataDelete()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en');
|
||||
$this->assertEquals(array(), $catalogue->getMetadata('', ''), 'Metadata is empty');
|
||||
$this->assertEquals([], $catalogue->getMetadata('', ''), 'Metadata is empty');
|
||||
$catalogue->deleteMetadata('key', 'messages');
|
||||
$catalogue->deleteMetadata('', 'messages');
|
||||
$catalogue->deleteMetadata();
|
||||
@@ -217,8 +217,8 @@ class MessageCatalogueTest extends TestCase
|
||||
$catalogue->setMetadata('key', 'value');
|
||||
$this->assertEquals('value', $catalogue->getMetadata('key', 'messages'), "Metadata 'key' = 'value'");
|
||||
|
||||
$catalogue->setMetadata('key2', array());
|
||||
$this->assertEquals(array(), $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array');
|
||||
$catalogue->setMetadata('key2', []);
|
||||
$this->assertEquals([], $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array');
|
||||
|
||||
$catalogue->deleteMetadata('key2', 'messages');
|
||||
$this->assertNull($catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.');
|
||||
@@ -231,13 +231,13 @@ class MessageCatalogueTest extends TestCase
|
||||
{
|
||||
$cat1 = new MessageCatalogue('en');
|
||||
$cat1->setMetadata('a', 'b');
|
||||
$this->assertEquals(array('messages' => array('a' => 'b')), $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.');
|
||||
$this->assertEquals(['messages' => ['a' => 'b']], $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.');
|
||||
|
||||
$cat2 = new MessageCatalogue('en');
|
||||
$cat2->setMetadata('b', 'c', 'domain');
|
||||
$this->assertEquals(array('domain' => array('b' => 'c')), $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.');
|
||||
$this->assertEquals(['domain' => ['b' => 'c']], $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.');
|
||||
|
||||
$cat1->addCatalogue($cat2);
|
||||
$this->assertEquals(array('messages' => array('a' => 'b'), 'domain' => array('b' => 'c')), $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.');
|
||||
$this->assertEquals(['messages' => ['a' => 'b'], 'domain' => ['b' => 'c']], $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,92 +49,92 @@ class MessageSelectorTest extends TestCase
|
||||
|
||||
public function getNonMatchingMessages()
|
||||
{
|
||||
return array(
|
||||
array('{0} There are no apples|{1} There is one apple', 2),
|
||||
array('{1} There is one apple|]1,Inf] There are %count% apples', 0),
|
||||
array('{1} There is one apple|]2,Inf] There are %count% apples', 2),
|
||||
array('{0} There are no apples|There is one apple', 2),
|
||||
);
|
||||
return [
|
||||
['{0} There are no apples|{1} There is one apple', 2],
|
||||
['{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['{1} There is one apple|]2,Inf] There are %count% apples', 2],
|
||||
['{0} There are no apples|There is one apple', 2],
|
||||
];
|
||||
}
|
||||
|
||||
public function getChooseTests()
|
||||
{
|
||||
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('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0),
|
||||
array('There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0),
|
||||
return [
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
|
||||
array('There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1),
|
||||
['There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1],
|
||||
|
||||
array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10),
|
||||
array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10),
|
||||
array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10),
|
||||
['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10],
|
||||
['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10],
|
||||
['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10],
|
||||
|
||||
array('There are %count% apples', 'There is one apple|There are %count% apples', 0),
|
||||
array('There is one apple', 'There is one apple|There are %count% apples', 1),
|
||||
array('There are %count% apples', 'There is one apple|There are %count% apples', 10),
|
||||
['There are %count% apples', 'There is one apple|There are %count% apples', 0],
|
||||
['There is one apple', 'There is one apple|There are %count% apples', 1],
|
||||
['There are %count% apples', 'There is one apple|There are %count% apples', 10],
|
||||
|
||||
array('There are %count% apples', 'one: There is one apple|more: There are %count% apples', 0),
|
||||
array('There is one apple', 'one: There is one apple|more: There are %count% apples', 1),
|
||||
array('There are %count% apples', 'one: There is one apple|more: There are %count% apples', 10),
|
||||
['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 0],
|
||||
['There is one apple', 'one: There is one apple|more: There are %count% apples', 1],
|
||||
['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 10],
|
||||
|
||||
array('There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0),
|
||||
array('There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1),
|
||||
array('There are %count% apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10),
|
||||
['There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0],
|
||||
['There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1],
|
||||
['There are %count% apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10],
|
||||
|
||||
array('', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0),
|
||||
array('', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1),
|
||||
['', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1],
|
||||
|
||||
// Indexed only tests which are Gettext PoFile* compatible strings.
|
||||
array('There are %count% apples', 'There is one apple|There are %count% apples', 0),
|
||||
array('There is one apple', 'There is one apple|There are %count% apples', 1),
|
||||
array('There are %count% apples', 'There is one apple|There are %count% apples', 2),
|
||||
['There are %count% apples', 'There is one apple|There are %count% apples', 0],
|
||||
['There is one apple', 'There is one apple|There are %count% apples', 1],
|
||||
['There are %count% apples', 'There is one apple|There are %count% apples', 2],
|
||||
|
||||
// Tests for float numbers
|
||||
array('There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7),
|
||||
array('There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1),
|
||||
array('There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7),
|
||||
array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0),
|
||||
array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0),
|
||||
array('There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0),
|
||||
['There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7],
|
||||
['There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1],
|
||||
['There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7],
|
||||
['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0],
|
||||
['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0],
|
||||
['There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0],
|
||||
|
||||
// Test texts with new-lines
|
||||
// with double-quotes and \n in id & double-quotes and actual newlines in text
|
||||
array("This is a text with a\n new-line in it. Selector = 0.", '{0}This is a text with a
|
||||
["This is a text with a\n new-line in it. Selector = 0.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 0),
|
||||
new-line in it. Selector > 1.', 0],
|
||||
// with double-quotes and \n in id and single-quotes and actual newlines in text
|
||||
array("This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a
|
||||
["This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 1),
|
||||
array("This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a
|
||||
new-line in it. Selector > 1.', 1],
|
||||
["This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 5),
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with double-quotes and id split accros lines
|
||||
array('This is a text with a
|
||||
['This is a text with a
|
||||
new-line in it. Selector = 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 1),
|
||||
new-line in it. Selector > 1.', 1],
|
||||
// with single-quotes and id split accros lines
|
||||
array('This is a text with a
|
||||
['This is a text with a
|
||||
new-line in it. Selector > 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 5),
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with single-quotes and \n in text
|
||||
array('This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0),
|
||||
['This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0],
|
||||
// with double-quotes and id split accros lines
|
||||
array("This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1),
|
||||
["This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1],
|
||||
// esacape pipe
|
||||
array('This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0),
|
||||
['This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0],
|
||||
// Empty plural set (2 plural forms) from a .PO file
|
||||
array('', '|', 1),
|
||||
['', '|', 1],
|
||||
// Empty plural set (3 plural forms) from a .PO file
|
||||
array('', '||', 1),
|
||||
);
|
||||
['', '||', 1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ class PluralizationRulesTest extends TestCase
|
||||
*/
|
||||
public function successLangcodes()
|
||||
{
|
||||
return array(
|
||||
array('1', array('ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky')),
|
||||
array('2', array('nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM')),
|
||||
array('3', array('be', 'bs', 'cs', 'hr')),
|
||||
array('4', array('cy', 'mt', 'sl')),
|
||||
array('6', array('ar')),
|
||||
);
|
||||
return [
|
||||
['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']],
|
||||
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM']],
|
||||
['3', ['be', 'bs', 'cs', 'hr']],
|
||||
['4', ['cy', 'mt', 'sl']],
|
||||
['6', ['ar']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,13 +81,13 @@ class PluralizationRulesTest extends TestCase
|
||||
*/
|
||||
public function failingLangcodes()
|
||||
{
|
||||
return array(
|
||||
array('1', array('fa')),
|
||||
array('2', array('jbo')),
|
||||
array('3', array('cbs')),
|
||||
array('4', array('gd', 'kw')),
|
||||
array('5', array('ga')),
|
||||
);
|
||||
return [
|
||||
['1', ['fa']],
|
||||
['2', ['jbo']],
|
||||
['3', ['cbs']],
|
||||
['4', ['gd', 'kw']],
|
||||
['5', ['ga']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class PluralizationRulesTest extends TestCase
|
||||
|
||||
protected function generateTestData($langCodes)
|
||||
{
|
||||
$matrix = array();
|
||||
$matrix = [];
|
||||
foreach ($langCodes as $langCode) {
|
||||
for ($count = 0; $count < 200; ++$count) {
|
||||
$plural = PluralizationRules::get($count, $langCode);
|
||||
|
||||
@@ -65,18 +65,18 @@ class TranslatorCacheTest extends TestCase
|
||||
// Prime the cache
|
||||
$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->addResource($format, [$msgid => 'OK'], $locale);
|
||||
$translator->addResource($format, [$msgid.'+intl' => 'OK'], $locale, 'messages+intl-icu');
|
||||
$translator->trans($msgid);
|
||||
$translator->trans($msgid.'+intl', array(), 'messages+intl-icu');
|
||||
$translator->trans($msgid.'+intl', [], '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');
|
||||
$translator->addResource($format, [$msgid => 'OK'], $locale);
|
||||
$translator->addResource($format, [$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'));
|
||||
$this->assertEquals('OK', $translator->trans($msgid.'+intl', [], 'messages+intl-icu'));
|
||||
}
|
||||
|
||||
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
|
||||
@@ -96,7 +96,7 @@ class TranslatorCacheTest extends TestCase
|
||||
$format = 'some_format';
|
||||
$msgid = 'test';
|
||||
|
||||
$catalogue = new MessageCatalogue($locale, array());
|
||||
$catalogue = new MessageCatalogue($locale, []);
|
||||
$catalogue->addResource(new StaleResource()); // better use a helper class than a mock, because it gets serialized in the cache and re-loaded
|
||||
|
||||
/** @var LoaderInterface|\PHPUnit_Framework_MockObject_MockObject $loader */
|
||||
@@ -137,26 +137,26 @@ class TranslatorCacheTest extends TestCase
|
||||
// Create a Translator and prime its cache
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, new ArrayLoader());
|
||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||
$translator->addResource($format, [$msgid => 'OK'], $locale);
|
||||
$translator->trans($msgid);
|
||||
|
||||
// Create another Translator with a different catalogue for the same locale
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, new ArrayLoader());
|
||||
$translator->addResource($format, array($msgid => 'FAIL'), $locale);
|
||||
$translator->addResource($format, [$msgid => 'FAIL'], $locale);
|
||||
$translator->trans($msgid);
|
||||
|
||||
// Now the first translator must still have a usable cache.
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, $this->createFailingLoader());
|
||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||
$translator->addResource($format, [$msgid => 'OK'], $locale);
|
||||
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
|
||||
}
|
||||
|
||||
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
|
||||
{
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
$translator->setFallbackLocales(array('b'));
|
||||
$translator->setFallbackLocales(['b']);
|
||||
$translator->trans('bar');
|
||||
|
||||
$cachedFiles = glob($this->tmpDir.'/*.php');
|
||||
@@ -172,24 +172,24 @@ class TranslatorCacheTest extends TestCase
|
||||
* loading a catalogue from the cache.
|
||||
*/
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
$translator->setFallbackLocales(array('b'));
|
||||
$translator->setFallbackLocales(['b']);
|
||||
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||
$translator->addResource('array', ['foo' => 'foo (a)'], 'a');
|
||||
$translator->addResource('array', ['bar' => 'bar (b)'], 'b');
|
||||
|
||||
$this->assertEquals('bar (b)', $translator->trans('bar'));
|
||||
|
||||
// Remove fallback locale
|
||||
$translator->setFallbackLocales(array());
|
||||
$translator->setFallbackLocales([]);
|
||||
$this->assertEquals('bar', $translator->trans('bar'));
|
||||
|
||||
// Use a fresh translator with no fallback locales, result should be the same
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (a)'), 'a');
|
||||
$translator->addResource('array', array('bar' => 'bar (b)'), 'b');
|
||||
$translator->addResource('array', ['foo' => 'foo (a)'], 'a');
|
||||
$translator->addResource('array', ['bar' => 'bar (b)'], 'b');
|
||||
|
||||
$this->assertEquals('bar', $translator->trans('bar'));
|
||||
}
|
||||
@@ -202,7 +202,7 @@ class TranslatorCacheTest extends TestCase
|
||||
* messages provided by the loader. This must also be the case when these catalogues
|
||||
* are (internally) read from a cache.
|
||||
*
|
||||
* Optimizations inside the translator must not change this behaviour.
|
||||
* Optimizations inside the translator must not change this behavior.
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -210,13 +210,13 @@ class TranslatorCacheTest extends TestCase
|
||||
* The catalogues contain distinct sets of messages.
|
||||
*/
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
$translator->setFallbackLocales(array('b'));
|
||||
$translator->setFallbackLocales(['b']);
|
||||
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$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');
|
||||
$translator->addResource('array', ['foo' => 'foo (a)'], 'a');
|
||||
$translator->addResource('array', ['foo' => 'foo (b)'], 'b');
|
||||
$translator->addResource('array', ['bar' => 'bar (b)'], 'b');
|
||||
$translator->addResource('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.
|
||||
@@ -229,13 +229,13 @@ class TranslatorCacheTest extends TestCase
|
||||
* Behind the scenes, the cache is used. But that should not matter, right?
|
||||
*/
|
||||
$translator = new Translator('a', null, $this->tmpDir);
|
||||
$translator->setFallbackLocales(array('b'));
|
||||
$translator->setFallbackLocales(['b']);
|
||||
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$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');
|
||||
$translator->addResource('array', ['foo' => 'foo (a)'], 'a');
|
||||
$translator->addResource('array', ['foo' => 'foo (b)'], 'b');
|
||||
$translator->addResource('array', ['bar' => 'bar (b)'], 'b');
|
||||
$translator->addResource('array', ['baz' => 'baz (b)'], 'b', 'messages+intl-icu');
|
||||
|
||||
$catalogue = $translator->getCatalogue('a');
|
||||
$this->assertFalse($catalogue->defines('bar'));
|
||||
@@ -253,7 +253,7 @@ class TranslatorCacheTest extends TestCase
|
||||
$loader
|
||||
->expects($this->exactly(2))
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('fr', array(), array($resource))));
|
||||
->will($this->returnValue($this->getCatalogue('fr', [], [$resource])));
|
||||
|
||||
// prime the cache
|
||||
$translator = new Translator('fr', null, $this->tmpDir, true);
|
||||
@@ -268,7 +268,7 @@ class TranslatorCacheTest extends TestCase
|
||||
$translator->trans('foo');
|
||||
}
|
||||
|
||||
protected function getCatalogue($locale, $messages, $resources = array())
|
||||
protected function getCatalogue($locale, $messages, $resources = [])
|
||||
{
|
||||
$catalogue = new MessageCatalogue($locale);
|
||||
foreach ($messages as $key => $translation) {
|
||||
@@ -283,7 +283,7 @@ class TranslatorCacheTest extends TestCase
|
||||
|
||||
public function runForDebugAndProduction()
|
||||
{
|
||||
return array(array(true), array(false));
|
||||
return [[true], [false]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
264
vendor/symfony/translation/Tests/TranslatorTest.php
vendored
264
vendor/symfony/translation/Tests/TranslatorTest.php
vendored
@@ -97,8 +97,8 @@ class TranslatorTest extends TestCase
|
||||
$translator = new Translator($locale);
|
||||
$translator->addLoader('loader-a', new ArrayLoader());
|
||||
$translator->addLoader('loader-b', new ArrayLoader());
|
||||
$translator->addResource('loader-a', array('foo' => 'foofoo'), $locale, 'domain-a');
|
||||
$translator->addResource('loader-b', array('bar' => 'foobar'), $locale, 'domain-b');
|
||||
$translator->addResource('loader-a', ['foo' => 'foofoo'], $locale, 'domain-a');
|
||||
$translator->addResource('loader-b', ['bar' => 'foobar'], $locale, 'domain-b');
|
||||
|
||||
/*
|
||||
* Test that we get a single catalogue comprising messages
|
||||
@@ -113,13 +113,13 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'fr');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'fr');
|
||||
|
||||
// force catalogue loading
|
||||
$translator->trans('bar');
|
||||
|
||||
$translator->setFallbackLocales(array('fr'));
|
||||
$translator->setFallbackLocales(['fr']);
|
||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
@@ -127,13 +127,13 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (en)'), 'en');
|
||||
$translator->addResource('array', array('bar' => 'bar (fr)'), 'fr');
|
||||
$translator->addResource('array', ['foo' => 'foo (en)'], 'en');
|
||||
$translator->addResource('array', ['bar' => 'bar (fr)'], 'fr');
|
||||
|
||||
// force catalogue loading
|
||||
$translator->trans('bar');
|
||||
|
||||
$translator->setFallbackLocales(array('fr_FR', 'fr'));
|
||||
$translator->setFallbackLocales(['fr_FR', 'fr']);
|
||||
$this->assertEquals('bar (fr)', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class TranslatorTest extends TestCase
|
||||
public function testSetFallbackInvalidLocales($locale)
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->setFallbackLocales(array('fr', $locale));
|
||||
$translator->setFallbackLocales(['fr', $locale]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +153,7 @@ class TranslatorTest extends TestCase
|
||||
public function testSetFallbackValidLocales($locale)
|
||||
{
|
||||
$translator = new Translator($locale);
|
||||
$translator->setFallbackLocales(array('fr', $locale));
|
||||
$translator->setFallbackLocales(['fr', $locale]);
|
||||
// no assertion. this method just asserts that no exception is thrown
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
@@ -161,10 +161,10 @@ class TranslatorTest extends TestCase
|
||||
public function testTransWithFallbackLocale()
|
||||
{
|
||||
$translator = new Translator('fr_FR');
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'en');
|
||||
|
||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||
}
|
||||
@@ -176,7 +176,7 @@ class TranslatorTest extends TestCase
|
||||
public function testAddResourceInvalidLocales($locale)
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), $locale);
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ class TranslatorTest extends TestCase
|
||||
public function testAddResourceValidLocales($locale)
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), $locale);
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], $locale);
|
||||
// no assertion. this method just asserts that no exception is thrown
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
@@ -195,12 +195,12 @@ class TranslatorTest extends TestCase
|
||||
$translator = new Translator('fr');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
$this->assertEquals('foofoo', $translator->trans('foo'));
|
||||
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'en');
|
||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
@@ -231,16 +231,16 @@ class TranslatorTest extends TestCase
|
||||
$translator->addResource($format, __DIR__.'/fixtures/non-existing', 'en_GB');
|
||||
$translator->addResource($format, __DIR__.'/fixtures/resources.'.$format, 'en', 'resources');
|
||||
|
||||
$this->assertEquals('bar', $translator->trans('foo', array(), 'resources'));
|
||||
$this->assertEquals('bar', $translator->trans('foo', [], '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');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en_GB');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'en_001');
|
||||
$translator->addResource('array', ['baz' => 'foobaz'], 'en');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('foobar', $translator->trans('bar'));
|
||||
$this->assertSame('foobaz', $translator->trans('baz'));
|
||||
@@ -250,10 +250,10 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en_GB_scouse');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'en_GB');
|
||||
$translator->addResource('array', ['baz' => 'foobaz'], 'en_001');
|
||||
$translator->addResource('array', ['qux' => 'fooqux'], 'en');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('foobar', $translator->trans('bar'));
|
||||
$this->assertSame('foobaz', $translator->trans('baz'));
|
||||
@@ -264,8 +264,8 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'az_Cyrl');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'az');
|
||||
$this->assertSame('foofoo', $translator->trans('foo'));
|
||||
$this->assertSame('bar', $translator->trans('bar'));
|
||||
}
|
||||
@@ -274,8 +274,8 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en_US');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en_US');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en_US');
|
||||
$translator->addResource('array', ['bar' => 'foobar'], 'en');
|
||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
@@ -283,10 +283,10 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('fr_FR');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (en_US)'), 'en_US');
|
||||
$translator->addResource('array', array('bar' => 'bar (en)'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foo (en_US)'], 'en_US');
|
||||
$translator->addResource('array', ['bar' => 'bar (en)'], 'en');
|
||||
|
||||
$translator->setFallbackLocales(array('en_US', 'en'));
|
||||
$translator->setFallbackLocales(['en_US', 'en']);
|
||||
|
||||
$this->assertEquals('foo (en_US)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (en)', $translator->trans('bar'));
|
||||
@@ -295,7 +295,7 @@ class TranslatorTest extends TestCase
|
||||
public function testTransNonExistentWithFallback()
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$this->assertEquals('non-existent', $translator->trans('non-existent'));
|
||||
}
|
||||
@@ -306,7 +306,7 @@ class TranslatorTest extends TestCase
|
||||
public function testWhenAResourceHasNoRegisteredLoader()
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
|
||||
$translator->trans('foo');
|
||||
}
|
||||
@@ -314,7 +314,7 @@ class TranslatorTest extends TestCase
|
||||
public function testNestedFallbackCatalogueWhenUsingMultipleLocales()
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->setFallbackLocales(array('ru', 'en'));
|
||||
$translator->setFallbackLocales(['ru', 'en']);
|
||||
|
||||
$translator->getCatalogue('fr');
|
||||
|
||||
@@ -329,7 +329,7 @@ class TranslatorTest extends TestCase
|
||||
$translator->addResource('yml', __DIR__.'/fixtures/resources.yml', 'en');
|
||||
|
||||
// force catalogue loading
|
||||
$this->assertEquals('bar', $translator->trans('foo', array()));
|
||||
$this->assertEquals('bar', $translator->trans('foo', []));
|
||||
|
||||
$resources = $translator->getCatalogue('en')->getResources();
|
||||
$this->assertCount(1, $resources);
|
||||
@@ -348,7 +348,7 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array((string) $id => $translation), $locale, $domain);
|
||||
$translator->addResource('array', [(string) $id => $translation], $locale, $domain);
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, $parameters, $domain, $locale));
|
||||
}
|
||||
@@ -361,9 +361,9 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
|
||||
$translator->trans('foo', array(), '', $locale);
|
||||
$translator->trans('foo', [], '', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,10 +373,10 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator($locale);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('test' => 'OK'), $locale);
|
||||
$translator->addResource('array', ['test' => 'OK'], $locale);
|
||||
|
||||
$this->assertEquals('OK', $translator->trans('test'));
|
||||
$this->assertEquals('OK', $translator->trans('test', array(), null, $locale));
|
||||
$this->assertEquals('OK', $translator->trans('test', [], null, $locale));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +388,7 @@ class TranslatorTest extends TestCase
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', $messages, 'fr', '');
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, array(), '', 'fr'));
|
||||
$this->assertEquals($expected, $translator->trans($id, [], '', 'fr'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +399,7 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array((string) $id => $translation), $locale, $domain);
|
||||
$translator->addResource('array', [(string) $id => $translation], $locale, $domain);
|
||||
|
||||
$this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale));
|
||||
}
|
||||
@@ -413,9 +413,9 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
|
||||
$translator->transChoice('foo', 1, array(), '', $locale);
|
||||
$translator->transChoice('foo', 1, [], '', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,118 +426,118 @@ class TranslatorTest extends TestCase
|
||||
{
|
||||
$translator = new Translator('en');
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], 'en');
|
||||
|
||||
$translator->transChoice('foo', 1, array(), '', $locale);
|
||||
$translator->transChoice('foo', 1, [], '', $locale);
|
||||
// no assertion. this method just asserts that no exception is thrown
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function getTransFileTests()
|
||||
{
|
||||
return array(
|
||||
array('csv', 'CsvFileLoader'),
|
||||
array('ini', 'IniFileLoader'),
|
||||
array('mo', 'MoFileLoader'),
|
||||
array('po', 'PoFileLoader'),
|
||||
array('php', 'PhpFileLoader'),
|
||||
array('ts', 'QtFileLoader'),
|
||||
array('xlf', 'XliffFileLoader'),
|
||||
array('yml', 'YamlFileLoader'),
|
||||
array('json', 'JsonFileLoader'),
|
||||
);
|
||||
return [
|
||||
['csv', 'CsvFileLoader'],
|
||||
['ini', 'IniFileLoader'],
|
||||
['mo', 'MoFileLoader'],
|
||||
['po', 'PoFileLoader'],
|
||||
['php', 'PhpFileLoader'],
|
||||
['ts', 'QtFileLoader'],
|
||||
['xlf', 'XliffFileLoader'],
|
||||
['yml', 'YamlFileLoader'],
|
||||
['json', 'JsonFileLoader'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransTests()
|
||||
{
|
||||
return array(
|
||||
array('Symfony est super !', 'Symfony is great!', 'Symfony est super !', array(), 'fr', ''),
|
||||
array('Symfony est awesome !', 'Symfony is %what%!', 'Symfony est %what% !', array('%what%' => 'awesome'), 'fr', ''),
|
||||
array('Symfony est super !', new StringClass('Symfony is great!'), 'Symfony est super !', array(), 'fr', ''),
|
||||
);
|
||||
return [
|
||||
['Symfony est super !', 'Symfony is great!', 'Symfony est super !', [], 'fr', ''],
|
||||
['Symfony est awesome !', 'Symfony is %what%!', 'Symfony est %what% !', ['%what%' => 'awesome'], 'fr', ''],
|
||||
['Symfony est super !', new StringClass('Symfony is great!'), 'Symfony est super !', [], 'fr', ''],
|
||||
];
|
||||
}
|
||||
|
||||
public function getFlattenedTransTests()
|
||||
{
|
||||
$messages = array(
|
||||
'symfony' => array(
|
||||
'is' => array(
|
||||
$messages = [
|
||||
'symfony' => [
|
||||
'is' => [
|
||||
'great' => 'Symfony est super!',
|
||||
),
|
||||
),
|
||||
'foo' => array(
|
||||
'bar' => array(
|
||||
],
|
||||
],
|
||||
'foo' => [
|
||||
'bar' => [
|
||||
'baz' => 'Foo Bar Baz',
|
||||
),
|
||||
],
|
||||
'baz' => 'Foo Baz',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return array(
|
||||
array('Symfony est super!', $messages, 'symfony.is.great'),
|
||||
array('Foo Bar Baz', $messages, 'foo.bar.baz'),
|
||||
array('Foo Baz', $messages, 'foo.baz'),
|
||||
);
|
||||
return [
|
||||
['Symfony est super!', $messages, 'symfony.is.great'],
|
||||
['Foo Bar Baz', $messages, 'foo.bar.baz'],
|
||||
['Foo Baz', $messages, 'foo.baz'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransChoiceTests()
|
||||
{
|
||||
return array(
|
||||
array('Il y a 0 pomme', '{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', ''),
|
||||
array('Il y a 1 pomme', '{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', 1, array(), 'fr', ''),
|
||||
array('Il y a 10 pommes', '{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', 10, array(), 'fr', ''),
|
||||
return [
|
||||
['Il y a 0 pomme', '{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, [], 'fr', ''],
|
||||
['Il y a 1 pomme', '{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', 1, [], 'fr', ''],
|
||||
['Il y a 10 pommes', '{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', 10, [], 'fr', ''],
|
||||
|
||||
array('Il y a 0 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 0, array(), 'fr', ''),
|
||||
array('Il y a 1 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 1, array(), 'fr', ''),
|
||||
array('Il y a 10 pommes', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 10, array(), 'fr', ''),
|
||||
['Il y a 0 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 0, [], 'fr', ''],
|
||||
['Il y a 1 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 1, [], 'fr', ''],
|
||||
['Il y a 10 pommes', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 10, [], 'fr', ''],
|
||||
|
||||
array('Il y a 0 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array(), 'fr', ''),
|
||||
array('Il y a 1 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array(), 'fr', ''),
|
||||
array('Il y a 10 pommes', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array(), 'fr', ''),
|
||||
['Il y a 0 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, [], 'fr', ''],
|
||||
['Il y a 1 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, [], 'fr', ''],
|
||||
['Il y a 10 pommes', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, [], 'fr', ''],
|
||||
|
||||
array('Il n\'y a aucune pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array(), 'fr', ''),
|
||||
array('Il y a 1 pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array(), 'fr', ''),
|
||||
array('Il y a 10 pommes', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array(), 'fr', ''),
|
||||
['Il n\'y a aucune pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, [], 'fr', ''],
|
||||
['Il y a 1 pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, [], 'fr', ''],
|
||||
['Il y a 10 pommes', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, [], 'fr', ''],
|
||||
|
||||
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', ''),
|
||||
['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, [], '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 quelques pommes', 2, array('%count%' => 'quelques'), 'fr', ''),
|
||||
);
|
||||
['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, ['%count%' => 'quelques'], 'fr', ''],
|
||||
];
|
||||
}
|
||||
|
||||
public function getInvalidLocalesTests()
|
||||
{
|
||||
return array(
|
||||
array('fr FR'),
|
||||
array('français'),
|
||||
array('fr+en'),
|
||||
array('utf#8'),
|
||||
array('fr&en'),
|
||||
array('fr~FR'),
|
||||
array(' fr'),
|
||||
array('fr '),
|
||||
array('fr*'),
|
||||
array('fr/FR'),
|
||||
array('fr\\FR'),
|
||||
);
|
||||
return [
|
||||
['fr FR'],
|
||||
['français'],
|
||||
['fr+en'],
|
||||
['utf#8'],
|
||||
['fr&en'],
|
||||
['fr~FR'],
|
||||
[' fr'],
|
||||
['fr '],
|
||||
['fr*'],
|
||||
['fr/FR'],
|
||||
['fr\\FR'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidLocalesTests()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array('fr'),
|
||||
array('francais'),
|
||||
array('FR'),
|
||||
array('frFR'),
|
||||
array('fr-FR'),
|
||||
array('fr_FR'),
|
||||
array('fr.FR'),
|
||||
array('fr-FR.UTF8'),
|
||||
array('sr@latin'),
|
||||
);
|
||||
return [
|
||||
[''],
|
||||
[null],
|
||||
['fr'],
|
||||
['francais'],
|
||||
['FR'],
|
||||
['frFR'],
|
||||
['fr-FR'],
|
||||
['fr_FR'],
|
||||
['fr.FR'],
|
||||
['fr-FR.UTF8'],
|
||||
['sr@latin'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,11 +548,11 @@ class TranslatorTest extends TestCase
|
||||
$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', ['some_message' => 'Hello %name%'], 'en');
|
||||
$this->assertSame('Hello Bob', $translator->trans('some_message', ['%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')));
|
||||
$translator->addResource('array', ['some_message' => 'Hi {name}'], 'en', 'messages+intl-icu');
|
||||
$this->assertSame('Hi Bob', $translator->trans('some_message', ['%name%' => 'Bob']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -561,11 +561,11 @@ class TranslatorTest extends TestCase
|
||||
public function testTransChoiceFallback()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
|
||||
$translator->addResource('array', ['some_message2' => 'one thing|%count% things'], 'en');
|
||||
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,11 +574,11 @@ class TranslatorTest extends TestCase
|
||||
public function testTransChoiceFallbackBis()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
$translator->setFallbackLocales(array('en_US', 'en'));
|
||||
$translator->setFallbackLocales(['en_US', 'en']);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en_US');
|
||||
$translator->addResource('array', ['some_message2' => 'one thing|%count% things'], 'en_US');
|
||||
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
|
||||
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,12 +587,12 @@ class TranslatorTest extends TestCase
|
||||
public function testTransChoiceFallbackWithNoTranslation()
|
||||
{
|
||||
$translator = new Translator('ru');
|
||||
$translator->setFallbackLocales(array('en'));
|
||||
$translator->setFallbackLocales(['en']);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
|
||||
// consistent behavior with Translator::trans(), which returns the string
|
||||
// unchanged if it can't be found
|
||||
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
|
||||
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,49 +26,49 @@ class ArrayConverterTest extends TestCase
|
||||
|
||||
public function messagesData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
// input
|
||||
array(
|
||||
[
|
||||
'foo1' => 'bar',
|
||||
'foo.bar' => 'value',
|
||||
),
|
||||
],
|
||||
// expected output
|
||||
array(
|
||||
[
|
||||
'foo1' => 'bar',
|
||||
'foo' => array('bar' => 'value'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'foo' => ['bar' => 'value'],
|
||||
],
|
||||
],
|
||||
[
|
||||
// input
|
||||
array(
|
||||
[
|
||||
'foo.bar' => 'value1',
|
||||
'foo.bar.test' => 'value2',
|
||||
),
|
||||
],
|
||||
// expected output
|
||||
array(
|
||||
'foo' => array(
|
||||
[
|
||||
'foo' => [
|
||||
'bar' => 'value1',
|
||||
'bar.test' => 'value2',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
// input
|
||||
array(
|
||||
[
|
||||
'foo.level2.level3.level4' => 'value1',
|
||||
'foo.level2' => 'value2',
|
||||
'foo.bar' => 'value3',
|
||||
),
|
||||
],
|
||||
// expected output
|
||||
array(
|
||||
'foo' => array(
|
||||
[
|
||||
'foo' => [
|
||||
'level2' => 'value2',
|
||||
'level2.level3.level4' => 'value1',
|
||||
'bar' => 'value3',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class TranslationWriterTest extends TestCase
|
||||
|
||||
class NonBackupDumper implements DumperInterface
|
||||
{
|
||||
public function dump(MessageCatalogue $messages, $options = array())
|
||||
public function dump(MessageCatalogue $messages, $options = [])
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class BackupDumper implements DumperInterface
|
||||
{
|
||||
public $backup = true;
|
||||
|
||||
public function dump(MessageCatalogue $messages, $options = array())
|
||||
public function dump(MessageCatalogue $messages, $options = [])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
This template is used for translation message extraction tests
|
||||
<?php echo $view['translator']->trans('single-quoted key'); ?>
|
||||
<?php echo $view['translator']->trans('double-quoted key'); ?>
|
||||
<?php echo $view['translator']->trans(<<<'EOF'
|
||||
<?php echo $view['translator']->trans(<<<EOF
|
||||
heredoc key
|
||||
EOF
|
||||
); ?>
|
||||
@@ -29,21 +29,31 @@ EOF
|
||||
<?php echo $view['translator']->transChoice(
|
||||
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
|
||||
10,
|
||||
array('%count%' => 10)
|
||||
['%count%' => 10]
|
||||
); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', array(), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->trans('concatenated'.' message'.<<<EOF
|
||||
with heredoc
|
||||
EOF
|
||||
.<<<'EOF'
|
||||
and nowdoc
|
||||
EOF
|
||||
); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('other-domain-test-no-params-long-array', array(), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('other-domain-test-params-short-array', array('foo' => 'bar'), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->trans('other-domain-test-no-params-long-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('other-domain-test-params-long-array', array('foo' => 'bar'), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->trans('other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-short-array-%count%', 10, array('%count%' => 10), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->trans('other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-long-array-%count%', 10, array('%count%' => 10), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-short-array-%count%', 10, ['%count%' => 10], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('typecast', array('a' => (int) '123'), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('msg1', 10 + 1, array(), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), array(), 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('other-domain-test-trans-choice-long-array-%count%', 10, ['%count%' => 10], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('typecast', ['a' => (int) '123'], 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('msg1', 10 + 1, [], 'not_messages'); ?>
|
||||
<?php echo $view['translator']->transChoice('msg2', ceil(4.5), [], 'not_messages'); ?>
|
||||
|
||||
<?php echo $view['translator']->trans('default domain', [], null); ?>
|
||||
|
||||
@@ -5,4 +5,7 @@ msgstr ""
|
||||
"Language: en\n"
|
||||
|
||||
msgid "foo"
|
||||
msgstr "bar"
|
||||
msgstr "bar"
|
||||
|
||||
msgid "bar"
|
||||
msgstr "foo"
|
||||
|
||||
Reference in New Issue
Block a user