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

Skip to content

Commit b0ae228

Browse files
committed
feature #38424 [Translation] Rename Translatable class to TranslatableMessage (natewiebe13)
This PR was submitted for the master branch but it was merged into the 5.x branch instead. Discussion ---------- [Translation] Rename Translatable class to TranslatableMessage | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #38342 | License | MIT | Doc PR | TBD This PR is in anticipation of #38342 passing. We'll need to also update the docs and the blog post here: https://symfony.com/blog/new-in-symfony-5-2-translatable-objects One extra note not discussed in the issue thread is the increase in the class name length shouldn't really be a problem as `t()` is likely to be used more often. Commits ------- 0d4e25f Rename Translatable class to TranslatableMessage
2 parents ca220a1 + 0d4e25f commit b0ae228

File tree

9 files changed

+56
-56
lines changed

9 files changed

+56
-56
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* added the `impersonation_exit_url()` and `impersonation_exit_path()` functions. They return a URL that allows to switch back to the original user.
88
* added the `workflow_transition()` function to easily retrieve a specific transition object
99
* added support for translating `TranslatableInterface` objects
10-
* added the `t()` function to easily create `Translatable` objects
10+
* added the `t()` function to easily create `TranslatableMessage` objects
1111
* Added support for extracting messages from the `t()` function
1212
* Added `field_*` Twig functions to access string values from Form fields
1313

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
1616
use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
1717
use Symfony\Bridge\Twig\TokenParser\TransTokenParser;
18-
use Symfony\Component\Translation\Translatable;
18+
use Symfony\Component\Translation\TranslatableMessage;
1919
use Symfony\Contracts\Translation\TranslatableInterface;
2020
use Symfony\Contracts\Translation\TranslatorInterface;
2121
use Symfony\Contracts\Translation\TranslatorTrait;
@@ -133,12 +133,12 @@ public function trans($message, $arguments = [], string $domain = null, string $
133133
return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
134134
}
135135

136-
public function createTranslatable(string $message, array $parameters = [], string $domain = null): Translatable
136+
public function createTranslatable(string $message, array $parameters = [], string $domain = null): TranslatableMessage
137137
{
138-
if (!class_exists(Translatable::class)) {
138+
if (!class_exists(TranslatableMessage::class)) {
139139
throw new \LogicException(sprintf('You cannot use the "%s" as the Translation Component is not installed. Try running "composer require symfony/translation".', __CLASS__));
140140
}
141141

142-
return new Translatable($message, $parameters, $domain);
142+
return new TranslatableMessage($message, $parameters, $domain);
143143
}
144144
}

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ CHANGELOG
66

77
* added support for calling `trans` with ICU formatted messages
88
* added `PseudoLocalizationTranslator`
9-
* added `Translatable` objects that represent a message that can be translated
10-
* added the `t()` function to easily create `Translatable` objects
11-
* Added support for extracting messages from `Translatable` objects
9+
* added `TranslatableMessage` objects that represent a message that can be translated
10+
* added the `t()` function to easily create `TranslatableMessage` objects
11+
* Added support for extracting messages from `TranslatableMessage` objects
1212

1313
5.1.0
1414
-----

src/Symfony/Component/Translation/Extractor/PhpExtractor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
5656
],
5757
[
5858
'new',
59-
'Translatable',
59+
'TranslatableMessage',
6060
'(',
6161
self::MESSAGE_TOKEN,
6262
',',
@@ -66,7 +66,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
6666
],
6767
[
6868
'new',
69-
'Translatable',
69+
'TranslatableMessage',
7070
'(',
7171
self::MESSAGE_TOKEN,
7272
],
@@ -79,7 +79,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
7979
'\\',
8080
'Translation',
8181
'\\',
82-
'Translatable',
82+
'TranslatableMessage',
8383
'(',
8484
self::MESSAGE_TOKEN,
8585
',',
@@ -89,7 +89,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
8989
],
9090
[
9191
'new',
92-
'\Symfony\Component\Translation\Translatable',
92+
'\Symfony\Component\Translation\TranslatableMessage',
9393
'(',
9494
self::MESSAGE_TOKEN,
9595
',',
@@ -106,13 +106,13 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
106106
'\\',
107107
'Translation',
108108
'\\',
109-
'Translatable',
109+
'TranslatableMessage',
110110
'(',
111111
self::MESSAGE_TOKEN,
112112
],
113113
[
114114
'new',
115-
'\Symfony\Component\Translation\Translatable',
115+
'\Symfony\Component\Translation\TranslatableMessage',
116116
'(',
117117
self::MESSAGE_TOKEN,
118118
],

src/Symfony/Component/Translation/Resources/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Nate Wiebe <[email protected]>
1616
*/
17-
function t(string $message, array $parameters = [], string $domain = null): Translatable
17+
function t(string $message, array $parameters = [], string $domain = null): TranslatableMessage
1818
{
19-
return new Translatable($message, $parameters, $domain);
19+
return new TranslatableMessage($message, $parameters, $domain);
2020
}

src/Symfony/Component/Translation/Tests/TranslatableTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Translation\Loader\ArrayLoader;
16-
use Symfony\Component\Translation\Translatable;
16+
use Symfony\Component\Translation\TranslatableMessage;
1717
use Symfony\Component\Translation\Translator;
1818

1919
class TranslatableTest extends TestCase
@@ -44,14 +44,14 @@ public function testFlattenedTrans($expected, $messages, $translatable)
4444

4545
public function testToString()
4646
{
47-
$this->assertSame('Symfony is great!', (string) new Translatable('Symfony is great!'));
47+
$this->assertSame('Symfony is great!', (string) new TranslatableMessage('Symfony is great!'));
4848
}
4949

5050
public function getTransTests()
5151
{
5252
return [
53-
['Symfony est super !', new Translatable('Symfony is great!', [], ''), 'Symfony est super !', 'fr'],
54-
['Symfony est awesome !', new Translatable('Symfony is %what%!', ['%what%' => 'awesome'], ''), 'Symfony est %what% !', 'fr'],
53+
['Symfony est super !', new TranslatableMessage('Symfony is great!', [], ''), 'Symfony est super !', 'fr'],
54+
['Symfony est awesome !', new TranslatableMessage('Symfony is %what%!', ['%what%' => 'awesome'], ''), 'Symfony est %what% !', 'fr'],
5555
];
5656
}
5757

@@ -72,9 +72,9 @@ public function getFlattenedTransTests()
7272
];
7373

7474
return [
75-
['Symfony est super!', $messages, new Translatable('symfony.is.great', [], '')],
76-
['Foo Bar Baz', $messages, new Translatable('foo.bar.baz', [], '')],
77-
['Foo Baz', $messages, new Translatable('foo.baz', [], '')],
75+
['Symfony est super!', $messages, new TranslatableMessage('symfony.is.great', [], '')],
76+
['Foo Bar Baz', $messages, new TranslatableMessage('foo.bar.baz', [], '')],
77+
['Foo Baz', $messages, new TranslatableMessage('foo.baz', [], '')],
7878
];
7979
}
8080
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
This template is used for translation message extraction tests
2-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn single-quoted key'); ?>
3-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn double-quoted key'); ?>
4-
<?php new \Symfony\Component\Translation\Translatable(<<<EOF
2+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn single-quoted key'); ?>
3+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn double-quoted key'); ?>
4+
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<EOF
55
translatable-fqn heredoc key
66
EOF
77
); ?>
8-
<?php new \Symfony\Component\Translation\Translatable(<<<'EOF'
8+
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<'EOF'
99
translatable-fqn nowdoc key
1010
EOF
1111
); ?>
12-
<?php new \Symfony\Component\Translation\Translatable(
12+
<?php new \Symfony\Component\Translation\TranslatableMessage(
1313
"translatable-fqn double-quoted key with whitespace and escaped \$\n\" sequences"
1414
); ?>
15-
<?php new \Symfony\Component\Translation\Translatable(
15+
<?php new \Symfony\Component\Translation\TranslatableMessage(
1616
'translatable-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences'
1717
); ?>
18-
<?php new \Symfony\Component\Translation\Translatable(<<<EOF
18+
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<EOF
1919
translatable-fqn heredoc key with whitespace and escaped \$\n sequences
2020
EOF
2121
); ?>
22-
<?php new \Symfony\Component\Translation\Translatable(<<<'EOF'
22+
<?php new \Symfony\Component\Translation\TranslatableMessage(<<<'EOF'
2323
translatable-fqn nowdoc key with whitespace and nonescaped \$\n sequences
2424
EOF
2525
); ?>
2626

27-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn single-quoted key with "quote mark at the end"'); ?>
27+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn single-quoted key with "quote mark at the end"'); ?>
2828

29-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn concatenated'.' message'.<<<EOF
29+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn concatenated'.' message'.<<<EOF
3030
with heredoc
3131
EOF
3232
.<<<'EOF'
3333
and nowdoc
3434
EOF
3535
); ?>
3636

37-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-no-params-short-array', [], 'not_messages'); ?>
37+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-no-params-short-array', [], 'not_messages'); ?>
3838

39-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-no-params-long-array', [], 'not_messages'); ?>
39+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-no-params-long-array', [], 'not_messages'); ?>
4040

41-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
41+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
4242

43-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
43+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
4444

45-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn typecast', ['a' => (int) '123'], 'not_messages'); ?>
45+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn typecast', ['a' => (int) '123'], 'not_messages'); ?>
4646

47-
<?php new \Symfony\Component\Translation\Translatable('translatable-fqn default domain', [], null); ?>
47+
<?php new \Symfony\Component\Translation\TranslatableMessage('translatable-fqn default domain', [], null); ?>
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
This template is used for translation message extraction tests
2-
<?php new Translatable('translatable single-quoted key'); ?>
3-
<?php new Translatable('translatable double-quoted key'); ?>
4-
<?php new Translatable(<<<EOF
2+
<?php new TranslatableMessage('translatable single-quoted key'); ?>
3+
<?php new TranslatableMessage('translatable double-quoted key'); ?>
4+
<?php new TranslatableMessage(<<<EOF
55
translatable heredoc key
66
EOF
77
); ?>
8-
<?php new Translatable(<<<'EOF'
8+
<?php new TranslatableMessage(<<<'EOF'
99
translatable nowdoc key
1010
EOF
1111
); ?>
12-
<?php new Translatable(
12+
<?php new TranslatableMessage(
1313
"translatable double-quoted key with whitespace and escaped \$\n\" sequences"
1414
); ?>
15-
<?php new Translatable(
15+
<?php new TranslatableMessage(
1616
'translatable single-quoted key with whitespace and nonescaped \$\n\' sequences'
1717
); ?>
18-
<?php new Translatable(<<<EOF
18+
<?php new TranslatableMessage(<<<EOF
1919
translatable heredoc key with whitespace and escaped \$\n sequences
2020
EOF
2121
); ?>
22-
<?php new Translatable(<<<'EOF'
22+
<?php new TranslatableMessage(<<<'EOF'
2323
translatable nowdoc key with whitespace and nonescaped \$\n sequences
2424
EOF
2525
); ?>
2626

27-
<?php new Translatable('translatable single-quoted key with "quote mark at the end"'); ?>
27+
<?php new TranslatableMessage('translatable single-quoted key with "quote mark at the end"'); ?>
2828

29-
<?php new Translatable('translatable concatenated'.' message'.<<<EOF
29+
<?php new TranslatableMessage('translatable concatenated'.' message'.<<<EOF
3030
with heredoc
3131
EOF
3232
.<<<'EOF'
3333
and nowdoc
3434
EOF
3535
); ?>
3636

37-
<?php new Translatable('translatable other-domain-test-no-params-short-array', [], 'not_messages'); ?>
37+
<?php new TranslatableMessage('translatable other-domain-test-no-params-short-array', [], 'not_messages'); ?>
3838

39-
<?php new Translatable('translatable other-domain-test-no-params-long-array', [], 'not_messages'); ?>
39+
<?php new TranslatableMessage('translatable other-domain-test-no-params-long-array', [], 'not_messages'); ?>
4040

41-
<?php new Translatable('translatable other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
41+
<?php new TranslatableMessage('translatable other-domain-test-params-short-array', ['foo' => 'bar'], 'not_messages'); ?>
4242

43-
<?php new Translatable('translatable other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
43+
<?php new TranslatableMessage('translatable other-domain-test-params-long-array', ['foo' => 'bar'], 'not_messages'); ?>
4444

45-
<?php new Translatable('translatable typecast', ['a' => (int) '123'], 'not_messages'); ?>
45+
<?php new TranslatableMessage('translatable typecast', ['a' => (int) '123'], 'not_messages'); ?>
4646

47-
<?php new Translatable('translatable default domain', [], null); ?>
47+
<?php new TranslatableMessage('translatable default domain', [], null); ?>

src/Symfony/Component/Translation/Translatable.php renamed to src/Symfony/Component/Translation/TranslatableMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @author Nate Wiebe <[email protected]>
1919
*/
20-
class Translatable implements TranslatableInterface
20+
class TranslatableMessage implements TranslatableInterface
2121
{
2222
private $message;
2323
private $parameters;

0 commit comments

Comments
 (0)