Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Translation] Rename Translatable class to TranslatableMessage #38424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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;
Expand Down Expand Up @@ -133,12 +133,12 @@ public function trans($message, $arguments = [], string $domain = null, string $
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 changes: 3 additions & 3 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Translation/Extractor/PhpExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
],
[
'new',
'Translatable',
'TranslatableMessage',
'(',
self::MESSAGE_TOKEN,
',',
Expand All @@ -66,7 +66,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
],
[
'new',
'Translatable',
'TranslatableMessage',
'(',
self::MESSAGE_TOKEN,
],
Expand All @@ -79,7 +79,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
'\\',
'Translation',
'\\',
'Translatable',
'TranslatableMessage',
'(',
self::MESSAGE_TOKEN,
',',
Expand All @@ -89,7 +89,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
],
[
'new',
'\Symfony\Component\Translation\Translatable',
'\Symfony\Component\Translation\TranslatableMessage',
'(',
self::MESSAGE_TOKEN,
',',
Expand All @@ -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,
],
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Translation/Resources/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Nate Wiebe <[email protected]>
*/
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);
}
14 changes: 7 additions & 7 deletions src/Symfony/Component/Translation/Tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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
Expand Down Expand Up @@ -44,14 +44,14 @@ public function testFlattenedTrans($expected, $messages, $translatable)

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'],
];
}

Expand All @@ -72,9 +72,9 @@ public function getFlattenedTransTests()
];

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', [], '')],
];
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
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'
and nowdoc
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); ?>
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
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'
and nowdoc
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); ?>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Nate Wiebe <[email protected]>
*/
class Translatable implements TranslatableInterface
class TranslatableMessage implements TranslatableInterface
{
private $message;
private $parameters;
Expand Down