@@ -361,30 +361,41 @@ private function createFakeFileForVueFiles(): void {
361361 continue ;
362362 }
363363
364- // t
365- preg_match_all ("/\Wt\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*[),]/ " , $ vueSource , $ singleQuoteMatches );
366- preg_match_all ("/\Wt\s*\(\s* \"?([\w.]+) \"?,\s* \"(.+) \"\s*[),]/ " , $ vueSource , $ doubleQuoteMatches );
367- preg_match_all ("/\Wt\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*[),]/msU " , $ vueSource , $ templateQuoteMatches );
368- $ matches0 = array_merge ($ singleQuoteMatches [0 ], $ doubleQuoteMatches [0 ], $ templateQuoteMatches [0 ]);
369- $ matches2 = array_merge ($ singleQuoteMatches [2 ], $ doubleQuoteMatches [2 ], $ templateQuoteMatches [2 ]);
370- foreach (array_keys ($ matches2 ) as $ k ) {
371- $ match = $ matches2 [$ k ];
372- $ fakeFileContent .= $ this ->getTranslatorHintWithVueSource ($ vueFile , $ vueSource , $ matches0 [$ k ]);
373- $ fakeFileContent .= "t(' " . $ this ->name . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match ) . "'); " . PHP_EOL ;
364+ $ matches = [];
365+ if (preg_match ('/<script[^>]*>(.+)<\/script>/s ' , $ vueSource , $ matches )) {
366+ $ fakeFileContent .= $ matches [1 ] . "; \n" ;
374367 }
375368
376- // n
377- preg_match_all ("/\Wn\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*,\s*'(.+)'\s*(.+)\s*[),]/ " , $ vueSource , $ singleQuoteMatches );
378- preg_match_all ("/\Wn\s*\(\s* \"?([\w.]+) \"?,\s* \"(.+) \"\s*,\s* \"(.+) \"\s*(.+)\s*[),]/ " , $ vueSource , $ doubleQuoteMatches );
379- preg_match_all ("/\Wn\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*,\s*`(.+)`\s*[),]/msU " , $ vueSource , $ templateQuoteMatches );
380- $ matches0 = array_merge ($ singleQuoteMatches [0 ], $ doubleQuoteMatches [0 ], $ templateQuoteMatches [0 ]);
381- $ matches2 = array_merge ($ singleQuoteMatches [2 ], $ doubleQuoteMatches [2 ], $ templateQuoteMatches [2 ]);
382- $ matches3 = array_merge ($ singleQuoteMatches [3 ], $ doubleQuoteMatches [3 ], $ templateQuoteMatches [3 ]);
383- foreach (array_keys ($ matches2 ) as $ k ) {
384- $ match2 = $ matches2 [$ k ];
385- $ match3 = $ matches3 [$ k ];
386- $ fakeFileContent .= $ this ->getTranslatorHintWithVueSource ($ vueFile , $ vueSource , $ matches0 [$ k ]);
387- $ fakeFileContent .= "n(' " . $ this ->name . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match2 ) . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match3 ) . "'); " . PHP_EOL ;
369+ if (preg_match ('/<template>(.+)<\/template>/s ' , $ vueSource , $ matches , PREG_OFFSET_CAPTURE )) {
370+ // Also parse the template but make sure we keep the correct line numbers for source references
371+ $ vueSource = str_repeat ("\n" , substr_count ($ vueSource , "\n" , 0 , $ matches [1 ][1 ]));
372+ $ vueSource .= $ matches [1 ][0 ];
373+
374+ // t
375+ preg_match_all ("/\Wt\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*[),]/ " , $ vueSource , $ singleQuoteMatches );
376+ preg_match_all ("/\Wt\s*\(\s* \"?([\w.]+) \"?,\s* \"(.+) \"\s*[),]/ " , $ vueSource , $ doubleQuoteMatches );
377+ preg_match_all ("/\Wt\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*[),]/msU " , $ vueSource , $ templateQuoteMatches );
378+ $ matches0 = array_merge ($ singleQuoteMatches [0 ], $ doubleQuoteMatches [0 ], $ templateQuoteMatches [0 ]);
379+ $ matches2 = array_merge ($ singleQuoteMatches [2 ], $ doubleQuoteMatches [2 ], $ templateQuoteMatches [2 ]);
380+ foreach (array_keys ($ matches2 ) as $ k ) {
381+ $ match = $ matches2 [$ k ];
382+ $ fakeFileContent .= $ this ->getTranslatorHintWithVueSource ($ vueFile , $ vueSource , $ matches0 [$ k ]);
383+ $ fakeFileContent .= "t(' " . $ this ->name . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match ) . "'); " . PHP_EOL ;
384+ }
385+
386+ // n
387+ preg_match_all ("/\Wn\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*,\s*'(.+)'\s*(.+)\s*[),]/ " , $ vueSource , $ singleQuoteMatches );
388+ preg_match_all ("/\Wn\s*\(\s* \"?([\w.]+) \"?,\s* \"(.+) \"\s*,\s* \"(.+) \"\s*(.+)\s*[),]/ " , $ vueSource , $ doubleQuoteMatches );
389+ preg_match_all ("/\Wn\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*,\s*`(.+)`\s*[),]/msU " , $ vueSource , $ templateQuoteMatches );
390+ $ matches0 = array_merge ($ singleQuoteMatches [0 ], $ doubleQuoteMatches [0 ], $ templateQuoteMatches [0 ]);
391+ $ matches2 = array_merge ($ singleQuoteMatches [2 ], $ doubleQuoteMatches [2 ], $ templateQuoteMatches [2 ]);
392+ $ matches3 = array_merge ($ singleQuoteMatches [3 ], $ doubleQuoteMatches [3 ], $ templateQuoteMatches [3 ]);
393+ foreach (array_keys ($ matches2 ) as $ k ) {
394+ $ match2 = $ matches2 [$ k ];
395+ $ match3 = $ matches3 [$ k ];
396+ $ fakeFileContent .= $ this ->getTranslatorHintWithVueSource ($ vueFile , $ vueSource , $ matches0 [$ k ]);
397+ $ fakeFileContent .= "n(' " . $ this ->name . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match2 ) . "', ' " . preg_replace ('/\s+/ ' , ' ' , $ match3 ) . "'); " . PHP_EOL ;
398+ }
388399 }
389400 }
390401
0 commit comments