@@ -25,14 +25,22 @@ class IdentityTranslator implements LegacyTranslatorInterface, TranslatorInterfa
25
25
use TranslatorTrait;
26
26
27
27
private $ selector ;
28
+ private $ debug = true ;
28
29
29
30
/**
30
- * @param MessageSelector|null $selector The message selector for pluralization
31
+ * @param MessageSelector|bool The message selector for pluralization or the debug boolean
31
32
*/
32
- public function __construct (MessageSelector $ selector = null )
33
+ public function __construct ()
33
34
{
34
- $ this ->selector = $ selector ;
35
-
35
+ $ args = func_get_args ();
36
+ if (isset ($ args [0 ])) {
37
+ if ($ args [0 ] instanceof MessageSelector) {
38
+ @trigger_error (sprintf ('Calling "%s()" is with a %s deprecated since Symfony 4.3. ' , MessageSelector::class, __METHOD__ ), E_USER_DEPRECATED );
39
+ $ this ->selector = $ args [0 ];
40
+ } elseif (is_bool ($ args [0 ])) {
41
+ $ this ->debug = $ args [0 ];
42
+ }
43
+ }
36
44
if (__CLASS__ !== \get_class ($ this )) {
37
45
@trigger_error (sprintf ('Calling "%s()" is deprecated since Symfony 4.2. ' , __METHOD__ ), E_USER_DEPRECATED );
38
46
}
@@ -50,8 +58,14 @@ public function transChoice($id, $number, array $parameters = [], $domain = null
50
58
if ($ this ->selector ) {
51
59
return strtr ($ this ->selector ->choose ((string ) $ id , $ number , $ locale ?: $ this ->getLocale ()), $ parameters );
52
60
}
53
-
54
- return $ this ->trans ($ id , ['%count% ' => $ number ] + $ parameters , $ domain , $ locale );
61
+ try {
62
+ return $ this ->trans ($ id , ['%count% ' => $ number ] + $ parameters , $ domain , $ locale );
63
+ } catch (\InvalidArgumentException $ e ) {
64
+ if ($ this ->debug ) {
65
+ throw $ e ;
66
+ }
67
+ return '' ;
68
+ }
55
69
}
56
70
57
71
private function getPluralizationRule (int $ number , string $ locale ): int
0 commit comments