Rename Translatable class to TranslatableMessage
This commit is contained in:
parent
ca220a1992
commit
0d4e25f4a6
@ -7,7 +7,7 @@ CHANGELOG
|
||||
* added the `impersonation_exit_url()` and `impersonation_exit_path()` functions. They return a URL that allows to switch back to the original user.
|
||||
* added the `workflow_transition()` function to easily retrieve a specific transition object
|
||||
* added support for translating `TranslatableInterface` objects
|
||||
* added the `t()` function to easily create `Translatable` objects
|
||||
* added the `t()` function to easily create `TranslatableMessage` objects
|
||||
* Added support for extracting messages from the `t()` function
|
||||
* Added `field_*` Twig functions to access string values from Form fields
|
||||
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
|
||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
||||
use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
|
||||
use Symfony\Bridge\Twig\TokenParser\TransTokenParser;
|
||||
use Symfony\Component\Translation\Translatable;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Contracts\Translation\TranslatableInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorTrait;
|
||||
@ -133,12 +133,12 @@ final class TranslationExtension extends AbstractExtension
|
||||
return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
|
||||
}
|
||||
|
||||
public function createTranslatable(string $message, array $parameters = [], string $domain = null): Translatable
|
||||
public function createTranslatable(string $message, array $parameters = [], string $domain = null): TranslatableMessage
|
||||
{
|
||||
if (!class_exists(Translatable::class)) {
|
||||
if (!class_exists(TranslatableMessage::class)) {
|
||||
throw new \LogicException(sprintf('You cannot use the "%s" as the Translation Component is not installed. Try running "composer require symfony/translation".', __CLASS__));
|
||||
}
|
||||
|
||||
return new Translatable($message, $parameters, $domain);
|
||||
return new TranslatableMessage($message, $parameters, $domain);
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ CHANGELOG
|
||||
|
||||
* added support for calling `trans` with ICU formatted messages
|
||||
* added `PseudoLocalizationTranslator`
|
||||
* added `Translatable` objects that represent a message that can be translated
|
||||
* added the `t()` function to easily create `Translatable` objects
|
||||
* Added support for extracting messages from `Translatable` objects
|
||||
* added `TranslatableMessage` objects that represent a message that can be translated
|
||||
* added the `t()` function to easily create `TranslatableMessage` objects
|
||||
* Added support for extracting messages from `TranslatableMessage` objects
|
||||
|
||||
5.1.0
|
||||
-----
|
||||
|
@ -56,7 +56,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'Translatable',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
@ -66,7 +66,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'Translatable',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
@ -79,7 +79,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
'\\',
|
||||
'Translation',
|
||||
'\\',
|
||||
'Translatable',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
@ -89,7 +89,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'\Symfony\Component\Translation\Translatable',
|
||||
'\Symfony\Component\Translation\TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
',',
|
||||
@ -106,13 +106,13 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
'\\',
|
||||
'Translation',
|
||||
'\\',
|
||||
'Translatable',
|
||||
'TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
[
|
||||
'new',
|
||||
'\Symfony\Component\Translation\Translatable',
|
||||
'\Symfony\Component\Translation\TranslatableMessage',
|
||||
'(',
|
||||
self::MESSAGE_TOKEN,
|
||||
],
|
||||
|
@ -14,7 +14,7 @@ namespace Symfony\Component\Translation;
|
||||
/**
|
||||
* @author Nate Wiebe <nate@northern.co>
|
||||
*/
|
||||
function t(string $message, array $parameters = [], string $domain = null): Translatable
|
||||
function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage
|
||||
{
|
||||
return new Translatable($message, $parameters, $domain);
|
||||
return new TranslatableMessage($message, $parameters, $domain);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Translation\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||
use Symfony\Component\Translation\Translatable;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
|
||||
class TranslatableTest extends TestCase
|
||||
@ -44,14 +44,14 @@ class TranslatableTest extends TestCase
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame('Symfony is great!', (string) new Translatable('Symfony is great!'));
|
||||
$this->assertSame('Symfony is great!', (string) new TranslatableMessage('Symfony is great!'));
|
||||
}
|
||||
|
||||
public function getTransTests()
|
||||
{
|
||||
return [
|
||||
['Symfony est super !', new Translatable('Symfony is great!', [], ''), 'Symfony est super !', 'fr'],
|
||||
['Symfony est awesome !', new Translatable('Symfony is %what%!', ['%what%' => 'awesome'], ''), 'Symfony est %what% !', 'fr'],
|
||||
['Symfony est super !', new TranslatableMessage('Symfony is great!', [], ''), 'Symfony est super !', 'fr'],
|
||||
['Symfony est awesome !', new TranslatableMessage('Symfony is %what%!', ['%what%' => 'awesome'], ''), 'Symfony est %what% !', 'fr'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -72,9 +72,9 @@ class TranslatableTest extends TestCase
|
||||
];
|
||||
|
||||
return [
|
||||
['Symfony est super!', $messages, new Translatable('symfony.is.great', [], '')],
|
||||
['Foo Bar Baz', $messages, new Translatable('foo.bar.baz', [], '')],
|
||||
['Foo Baz', $messages, new Translatable('foo.baz', [], '')],
|
||||
['Symfony est super!', $messages, new TranslatableMessage('symfony.is.great', [], '')],
|
||||
['Foo Bar Baz', $messages, new TranslatableMessage('foo.bar.baz', [], '')],
|
||||
['Foo Baz', $messages, new TranslatableMessage('foo.baz', [], '')],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
This template is used for translation message extraction tests
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn single-quoted key'); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn double-quoted key'); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(<<<EOF
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn single-quoted key'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn double-quoted key'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<EOF
|
||||
translatable-fqn heredoc key
|
||||
EOF
|
||||
); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(<<<'EOF'
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<'EOF'
|
||||
translatable-fqn nowdoc key
|
||||
EOF
|
||||
); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(
|
||||
"translatable-fqn double-quoted key with whitespace and escaped \$\n\" sequences"
|
||||
); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(
|
||||
'translatable-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences'
|
||||
); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(<<<EOF
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<EOF
|
||||
translatable-fqn heredoc key with whitespace and escaped \$\n sequences
|
||||
EOF
|
||||
); ?>
|
||||
<?php new \Symfony\Component\Translation\Translatable(<<<'EOF'
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<'EOF'
|
||||
translatable-fqn nowdoc key with whitespace and nonescaped \$\n sequences
|
||||
EOF
|
||||
); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn single-quoted key with "quote mark at the end"'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn single-quoted key with "quote mark at the end"'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn concatenated'.' message'.<<<EOF
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn concatenated'.' message'.<<<EOF
|
||||
with heredoc
|
||||
EOF
|
||||
.<<<'EOF'
|
||||
@ -34,14 +34,14 @@ EOF
|
||||
EOF
|
||||
); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-no-params-short-array', [], 'not_messages'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-no-params-short-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-no-params-long-array', [], 'not_messages'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-no-params-long-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn typecast', ['a' => (int) '123'], 'not_messages'); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn typecast', ['a' => (int) '123'], 'not_messages'); ?>
|
||||
|
||||
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn default domain', [], null); ?>
|
||||
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn default domain', [], null); ?>
|
||||
|
@ -1,32 +1,32 @@
|
||||
This template is used for translation message extraction tests
|
||||
<?php new Translatable('translatable single-quoted key'); ?>
|
||||
<?php new Translatable('translatable double-quoted key'); ?>
|
||||
<?php new Translatable(<<<EOF
|
||||
<?php new TranslatableMessage('translatable single-quoted key'); ?>
|
||||
<?php new TranslatableMessage('translatable double-quoted key'); ?>
|
||||
<?php new TranslatableMessage(<<<EOF
|
||||
translatable heredoc key
|
||||
EOF
|
||||
); ?>
|
||||
<?php new Translatable(<<<'EOF'
|
||||
<?php new TranslatableMessage(<<<'EOF'
|
||||
translatable nowdoc key
|
||||
EOF
|
||||
); ?>
|
||||
<?php new Translatable(
|
||||
<?php new TranslatableMessage(
|
||||
"translatable double-quoted key with whitespace and escaped \$\n\" sequences"
|
||||
); ?>
|
||||
<?php new Translatable(
|
||||
<?php new TranslatableMessage(
|
||||
'translatable single-quoted key with whitespace and nonescaped \$\n\' sequences'
|
||||
); ?>
|
||||
<?php new Translatable(<<<EOF
|
||||
<?php new TranslatableMessage(<<<EOF
|
||||
translatable heredoc key with whitespace and escaped \$\n sequences
|
||||
EOF
|
||||
); ?>
|
||||
<?php new Translatable(<<<'EOF'
|
||||
<?php new TranslatableMessage(<<<'EOF'
|
||||
translatable nowdoc key with whitespace and nonescaped \$\n sequences
|
||||
EOF
|
||||
); ?>
|
||||
|
||||
<?php new Translatable('translatable single-quoted key with "quote mark at the end"'); ?>
|
||||
<?php new TranslatableMessage('translatable single-quoted key with "quote mark at the end"'); ?>
|
||||
|
||||
<?php new Translatable('translatable concatenated'.' message'.<<<EOF
|
||||
<?php new TranslatableMessage('translatable concatenated'.' message'.<<<EOF
|
||||
with heredoc
|
||||
EOF
|
||||
.<<<'EOF'
|
||||
@ -34,14 +34,14 @@ EOF
|
||||
EOF
|
||||
); ?>
|
||||
|
||||
<?php new Translatable('translatable other-domain-test-no-params-short-array', [], 'not_messages'); ?>
|
||||
<?php new TranslatableMessage('translatable other-domain-test-no-params-short-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php new Translatable('translatable other-domain-test-no-params-long-array', [], 'not_messages'); ?>
|
||||
<?php new TranslatableMessage('translatable other-domain-test-no-params-long-array', [], 'not_messages'); ?>
|
||||
|
||||
<?php new Translatable('translatable other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
<?php new TranslatableMessage('translatable other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php new Translatable('translatable other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
<?php new TranslatableMessage('translatable other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
|
||||
|
||||
<?php new Translatable('translatable typecast', ['a' => (int) '123'], 'not_messages'); ?>
|
||||
<?php new TranslatableMessage('translatable typecast', ['a' => (int) '123'], 'not_messages'); ?>
|
||||
|
||||
<?php new Translatable('translatable default domain', [], null); ?>
|
||||
<?php new TranslatableMessage('translatable default domain', [], null); ?>
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
/**
|
||||
* @author Nate Wiebe <nate@northern.co>
|
||||
*/
|
||||
class Translatable implements TranslatableInterface
|
||||
class TranslatableMessage implements TranslatableInterface
|
||||
{
|
||||
private $message;
|
||||
private $parameters;
|
Reference in New Issue
Block a user