@@ -41,7 +41,7 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV
4141 * @var FileSourceFactory
4242 */
4343 private $ fileSourceFactory ;
44-
44+
4545 /**
4646 * @var DocParser
4747 */
@@ -116,6 +116,10 @@ public function enterNode(Node $node)
116116 if ($ node instanceof Node \Expr \Array_) {
117117 // first check if a translation_domain is set for this field
118118 $ domain = $ this ->getDomain ($ node );
119+ $ choiceDomain = $ this ->getChoiceDomain ($ node );
120+ if ($ choiceDomain === null ) {
121+ $ choiceDomain = $ domain ;
122+ }
119123
120124 // look for options containing a message
121125 foreach ($ node ->items as $ item ) {
@@ -138,7 +142,7 @@ public function enterNode(Node $node)
138142 $ this ->parseItem ($ item , $ domain );
139143 break ;
140144 case 'choices ' :
141- if ($ this ->parseChoiceNode ($ item , $ node , $ domain )) {
145+ if ($ this ->parseChoiceNode ($ item , $ node , $ choiceDomain )) {
142146 continue 2 ;
143147 }
144148 $ this ->parseItem ($ item , $ domain );
@@ -159,6 +163,20 @@ public function enterNode(Node $node)
159163 * @return null|string
160164 */
161165 public function getDomain (Node $ node )
166+ {
167+ return $ this ->getDomainValueForKey ('translation_domain ' , $ node );
168+ }
169+
170+ /**
171+ * @param Node $node
172+ * @return null|string
173+ */
174+ public function getChoiceDomain (Node $ node )
175+ {
176+ return $ this ->getDomainValueForKey ('choice_translation_domain ' , $ node );
177+ }
178+
179+ private function getDomainValueForKey ($ key , Node $ node )
162180 {
163181 $ domain = null ;
164182
@@ -167,7 +185,11 @@ public function getDomain(Node $node)
167185 continue ;
168186 }
169187
170- if ('translation_domain ' === $ item ->key ->value ) {
188+ if ($ key === $ item ->key ->value ) {
189+ if ($ item ->value instanceof Node \Expr \ConstFetch && $ item ->value ->name ->parts [0 ] === 'false ' ) {
190+ $ domain = false ;
191+ break ;
192+ }
171193 if (!$ item ->value instanceof Node \Scalar \String_) {
172194 continue ;
173195 }
@@ -210,7 +232,7 @@ protected function parseEmptyValueNode(Node $item, $domain)
210232 }
211233
212234 /**
213- * This parses any Node of type choices.
235+ * This parses any Node of type choices.
214236 *
215237 * Returning true means either that regardless of whether
216238 * parsing has occurred or not, the enterNode function should move on to the next node item.
@@ -252,7 +274,7 @@ protected function parseChoiceNode(Node $item, Node $node, $domain)
252274 }
253275
254276 /**
255- * This parses any Node of type attr
277+ * This parses any Node of type attr
256278 *
257279 * Returning true means either that regardless of whether
258280 * parsing has occurred or not, the enterNode function should move on to the next node item.
@@ -385,6 +407,11 @@ private function parseItem($item, $domain = null)
385407 throw new RuntimeException ($ message );
386408 }
387409
410+ if ($ domain === false ) {
411+ // Don't translate when domain is `false`
412+ return ;
413+ }
414+
388415 $ source = $ this ->fileSourceFactory ->create ($ this ->file , $ item ->value ->getLine ());
389416 $ id = $ item ->value ->value ;
390417
0 commit comments