@@ -41,7 +41,7 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV
4141 * @var FileSourceFactory
4242 */
4343 private $ fileSourceFactory ;
44-
44+
4545 /**
4646 * @var DocParser
4747 */
@@ -117,6 +117,10 @@ public function enterNode(Node $node)
117117 if ($ node instanceof Node \Expr \Array_) {
118118 // first check if a translation_domain is set for this field
119119 $ domain = $ this ->getDomain ($ node );
120+ $ choiceDomain = $ this ->getChoiceDomain ($ node );
121+ if ($ choiceDomain === null ) {
122+ $ choiceDomain = $ domain ;
123+ }
120124
121125 // look for options containing a message
122126 foreach ($ node ->items as $ item ) {
@@ -139,7 +143,7 @@ public function enterNode(Node $node)
139143 $ this ->parseItem ($ item , $ domain );
140144 break ;
141145 case 'choices ' :
142- if ($ this ->parseChoiceNode ($ item , $ node , $ domain )) {
146+ if ($ this ->parseChoiceNode ($ item , $ node , $ choiceDomain )) {
143147 continue 2 ;
144148 }
145149 $ this ->parseItem ($ item , $ domain );
@@ -160,6 +164,20 @@ public function enterNode(Node $node)
160164 * @return null|string
161165 */
162166 public function getDomain (Node $ node )
167+ {
168+ return $ this ->getDomainValueForKey ('translation_domain ' , $ node );
169+ }
170+
171+ /**
172+ * @param Node $node
173+ * @return null|string
174+ */
175+ public function getChoiceDomain (Node $ node )
176+ {
177+ return $ this ->getDomainValueForKey ('choice_translation_domain ' , $ node );
178+ }
179+
180+ private function getDomainValueForKey ($ key , Node $ node )
163181 {
164182 $ domain = null ;
165183
@@ -168,7 +186,11 @@ public function getDomain(Node $node)
168186 continue ;
169187 }
170188
171- if ('translation_domain ' === $ item ->key ->value ) {
189+ if ($ key === $ item ->key ->value ) {
190+ if ($ item ->value instanceof Node \Expr \ConstFetch && $ item ->value ->name ->parts [0 ] === 'false ' ) {
191+ $ domain = false ;
192+ break ;
193+ }
172194 if (!$ item ->value instanceof Node \Scalar \String_) {
173195 continue ;
174196 }
@@ -211,7 +233,7 @@ protected function parseEmptyValueNode(Node $item, $domain)
211233 }
212234
213235 /**
214- * This parses any Node of type choices.
236+ * This parses any Node of type choices.
215237 *
216238 * Returning true means either that regardless of whether
217239 * parsing has occurred or not, the enterNode function should move on to the next node item.
@@ -253,7 +275,7 @@ protected function parseChoiceNode(Node $item, Node $node, $domain)
253275 }
254276
255277 /**
256- * This parses any Node of type attr
278+ * This parses any Node of type attr
257279 *
258280 * Returning true means either that regardless of whether
259281 * parsing has occurred or not, the enterNode function should move on to the next node item.
@@ -395,6 +417,11 @@ private function parseItem($item, $domain = null)
395417 throw new RuntimeException ($ message );
396418 }
397419
420+ if ($ domain === false ) {
421+ // Don't translate when domain is `false`
422+ return ;
423+ }
424+
398425 $ source = $ this ->fileSourceFactory ->create ($ this ->file , $ item ->value ->getLine ());
399426 $ id = $ item ->value ->value ;
400427
0 commit comments