Skip to content

Commit

Permalink
Merge pull request #621 from nextcloud/fix/sanitize-vue-l10n
Browse files Browse the repository at this point in the history
fix(translations): sanitize vue translations hints
  • Loading branch information
nickvergessen authored Jan 12, 2024
2 parents 6d4838b + 9e7c675 commit 98c579e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions translations/translationtool/src/translationtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,20 @@ private function getTranslatorHintWithVueSource(string $vueFile, string $content
// <!-- TRANSLATORS : This is a comment -->
// <!-- TRANSLATORS This is a comment -->
// t('forms', 'Save to home') // TRANSLATORS: Export the file to the home path
$re = '/TRANSLATORS[: ]*(.*)(-->|\n)?/m';
$re = '/TRANSLATORS[: ]*(.*)/m';
preg_match_all($re, $searchComment, $matches, PREG_SET_ORDER, 0);

// If we have a comment, we use it
if (count($matches) > 0 && count($matches[0]) > 1) {
// Remove double spaces
return str_replace(' ', ' ', '// TRANSLATORS ' . $matches[0][1] . " ($relativeVuePath:$lineNumber)" . PHP_EOL);
$comment = str_replace(' ', ' ', $matches[0][1]);
// Remove leading and trailing spaces
$comment = trim($comment);
// Remove newlines
$comment = str_replace("\n", '', $comment);
// Remove html end comment
$comment = str_replace('-->', '', $comment);
return str_replace(' ', ' ', '// TRANSLATORS ' . $comment . " ($relativeVuePath:$lineNumber)" . PHP_EOL);
}

return '// TRANSLATORS ' . $relativeVuePath . ':' . $lineNumber . PHP_EOL;
Expand Down
Binary file modified translations/translationtool/translationtool.phar
Binary file not shown.

0 comments on commit 98c579e

Please sign in to comment.