Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8224b8

Browse files
committed
bug#31761 [TwigBridge] suggest Translation Component when TranslationExtension is used (nicolas-grekas)
This PR was merged into the 4.3 branch.Discussion----------[TwigBridge] suggest Translation Component when TranslationExtension is used| Q | A| ------------- | ---| Branch? | 4.3| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#31754| License | MIT| Doc PR | -Commits-------d4a9e7e [TwigBridge] suggest Translation Component when TranslationExtension is used
2 parents2a93351 +d4a9e7e commitd8224b8

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ public function __construct($translator = null, NodeVisitorInterface $translatio
4949
}
5050

5151
/**
52-
* @deprecated since Symfony 4.2
52+
* @return TranslatorInterface|null
5353
*/
5454
publicfunctiongetTranslator()
5555
{
56-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.',__METHOD__),E_USER_DEPRECATED);
56+
if (null ===$this->translator) {
57+
if (!interface_exists(TranslatorInterface::class)) {
58+
thrownew \LogicException(sprintf('You cannot use the "%s" if the Translation Contracts are not available. Try running "composer require symfony/translation".',__CLASS__));
59+
}
60+
61+
$this->translator =newclass()implements TranslatorInterface {
62+
use TranslatorTrait;
63+
};
64+
}
5765

5866
return$this->translator;
5967
}
@@ -108,31 +116,22 @@ public function trans($message, array $arguments = [], $domain = null, $locale =
108116
if (null !==$count) {
109117
$arguments['%count%'] =$count;
110118
}
111-
if (null ===$this->translator) {
112-
$this->translator =newclass()implements TranslatorInterface {
113-
use TranslatorTrait;
114-
};
115-
}
116119

117-
return$this->translator->trans($message,$arguments,$domain,$locale);
120+
return$this->getTranslator()->trans($message,$arguments,$domain,$locale);
118121
}
119122

120123
/**
121124
* @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
122125
*/
123126
publicfunctiontranschoice($message,$count,array$arguments = [],$domain =null,$locale =null)
124127
{
125-
if (null ===$this->translator) {
126-
$this->translator =newclass()implements TranslatorInterface {
127-
use TranslatorTrait;
128-
};
129-
}
128+
$translator =$this->getTranslator();
130129

131-
if ($this->translatorinstanceof TranslatorInterface) {
132-
return$this->translator->trans($message,array_merge(['%count%' =>$count],$arguments),$domain,$locale);
130+
if ($translatorinstanceof TranslatorInterface) {
131+
return$translator->trans($message,array_merge(['%count%' =>$count],$arguments),$domain,$locale);
133132
}
134133

135-
return$this->translator->transChoice($message,$count,array_merge(['%count%' =>$count],$arguments),$domain,$locale);
134+
return$translator->transChoice($message,$count,array_merge(['%count%' =>$count],$arguments),$domain,$locale);
136135
}
137136

138137
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp