Skip to content

Commit

Permalink
fixup! Allow vue-translator comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jotoeri committed Mar 2, 2021
1 parent 7544e13 commit b437a95
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions translations/translationtool/src/translationtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,11 @@ private function createFakeFileForVueFiles() {
$regexMatches = preg_grep($regex, $vueSource);

foreach ($regexMatches as $lineNum => $match) {
// Check for comment in previous line. Either HTML or JS comment. HTML-Comments terminate with '-->', JS do not
if(preg_match("/\W(TRANSLATORS)\s(.+)(-->)/", $vueSource[$lineNum-1], $commentSplit)
|| preg_match("/\W(TRANSLATORS)\s(.+)/", $vueSource[$lineNum-1], $commentSplit)) {

// Insert comment
$fakeFileContent .= "// TRANSLATORS " . preg_replace('/\s+/', ' ', $commentSplit[2]) . PHP_EOL;
// Check for comment in previous line. Either HTML or JS comment.
if(preg_match("/\W(\/\/|\/\*|<!--)\s(TRANSLATORS)\s(.+)/", $vueSource[$lineNum-1], $commentSplit)) {
// Remove possible comment-end-tags and insert comment
$commentText = preg_replace('/\s*(-->|\*\/)\s*/', '', $commentSplit[3]);
$fakeFileContent .= "// TRANSLATORS " . preg_replace('/\s+/', ' ', $commentText) . PHP_EOL;
}

// Insert translation-function
Expand All @@ -360,12 +359,11 @@ private function createFakeFileForVueFiles() {
$regexMatches = preg_grep($regex, $vueSource);

foreach ($regexMatches as $lineNum => $match) {
// Check for comment in previous line. Either HTML or JS comment. HTML-Comments terminate with '-->', JS do not
if(preg_match("/\W(TRANSLATORS)\s(.+)(-->)/", $vueSource[$lineNum-1], $commentSplit)
|| preg_match("/\W(TRANSLATORS)\s(.+)/", $vueSource[$lineNum-1], $commentSplit)) {

// Insert comment
$fakeFileContent .= "// TRANSLATORS " . preg_replace('/\s+/', ' ', $commentSplit[2]) . PHP_EOL;
// Check for comment in previous line. Either HTML or JS comment.
if(preg_match("/\W(\/\/|\/\*|<!--)\s(TRANSLATORS)\s(.+)/", $vueSource[$lineNum-1], $commentSplit)) {
// Remove possible comment-end-tags and insert comment
$commentText = preg_replace('/\s*(-->|\*\/)\s*/', '', $commentSplit[3]);
$fakeFileContent .= "// TRANSLATORS " . preg_replace('/\s+/', ' ', $commentText) . PHP_EOL;
}

// Insert translation-function
Expand Down

0 comments on commit b437a95

Please sign in to comment.