Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions translations/translationtool/src/translationtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,30 +361,41 @@ private function createFakeFileForVueFiles(): void {
continue;
}

// t
preg_match_all("/\Wt\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*[),]/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"\s*[),]/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*[),]/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
foreach (array_keys($matches2) as $k) {
$match = $matches2[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "t('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match) . "');" . PHP_EOL;
$matches = [];
if (preg_match('/<script[^>]*>(.+)<\/script>/s', $vueSource, $matches)) {
$fakeFileContent .= $matches[1] . ";\n";
}

// n
preg_match_all("/\Wn\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*,\s*'(.+)'\s*(.+)\s*[),]/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"\s*,\s*\"(.+)\"\s*(.+)\s*[),]/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*,\s*`(.+)`\s*[),]/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
$matches3 = array_merge($singleQuoteMatches[3], $doubleQuoteMatches[3], $templateQuoteMatches[3]);
foreach (array_keys($matches2) as $k) {
$match2 = $matches2[$k];
$match3 = $matches3[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "n('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match2) . "', '" . preg_replace('/\s+/', ' ', $match3) . "');" . PHP_EOL;
if (preg_match('/<template>(.+)<\/template>/s', $vueSource, $matches, PREG_OFFSET_CAPTURE)) {
// Also parse the template but make sure we keep the correct line numbers for source references
$vueSource = str_repeat("\n", substr_count($vueSource, "\n", 0, $matches[1][1]));
$vueSource .= $matches[1][0];

// t
preg_match_all("/\Wt\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*[),]/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"\s*[),]/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wt\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*[),]/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
foreach (array_keys($matches2) as $k) {
$match = $matches2[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "t('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match) . "');" . PHP_EOL;
}

// n
preg_match_all("/\Wn\s*\(\s*'?([\w.]+)'?,\s*'(.+)'\s*,\s*'(.+)'\s*(.+)\s*[),]/", $vueSource, $singleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*\"?([\w.]+)\"?,\s*\"(.+)\"\s*,\s*\"(.+)\"\s*(.+)\s*[),]/", $vueSource, $doubleQuoteMatches);
preg_match_all("/\Wn\s*\(\s*'?([\w.]+)'?\s*,\s*`(.+)`\s*,\s*`(.+)`\s*[),]/msU", $vueSource, $templateQuoteMatches);
$matches0 = array_merge($singleQuoteMatches[0], $doubleQuoteMatches[0], $templateQuoteMatches[0]);
$matches2 = array_merge($singleQuoteMatches[2], $doubleQuoteMatches[2], $templateQuoteMatches[2]);
$matches3 = array_merge($singleQuoteMatches[3], $doubleQuoteMatches[3], $templateQuoteMatches[3]);
foreach (array_keys($matches2) as $k) {
$match2 = $matches2[$k];
$match3 = $matches3[$k];
$fakeFileContent .= $this->getTranslatorHintWithVueSource($vueFile, $vueSource, $matches0[$k]);
$fakeFileContent .= "n('" . $this->name . "', '" . preg_replace('/\s+/', ' ', $match2) . "', '" . preg_replace('/\s+/', ' ', $match3) . "');" . PHP_EOL;
}
}
}

Expand Down
36 changes: 27 additions & 9 deletions translations/translationtool/tests/expected.pot
Original file line number Diff line number Diff line change
Expand Up @@ -45,51 +45,69 @@ msgid_plural "PHP %n Plurals with positional %1$s"
msgstr[0] ""
msgstr[1] ""

#: specialVueFakeDummyForL10nScript.js:8
msgid "one string"
msgid_plural "%n strings"
msgstr[0] ""
msgstr[1] ""

#. TRANSLATORS VUE string with plain text (src/vue.vue:8)
#: specialVueFakeDummyForL10nScript.js:2
#: specialVueFakeDummyForL10nScript.js:17
msgid "VUE String"
msgstr ""

#. TRANSLATORS VUE string with parameters (src/vue.vue:10)
#: specialVueFakeDummyForL10nScript.js:4
#: specialVueFakeDummyForL10nScript.js:19
msgid "VUE String with inline {parameter}"
msgstr ""

#. TRANSLATORS VUE string with wrapped parameters (src/vue.vue:12)
#: specialVueFakeDummyForL10nScript.js:6
#: specialVueFakeDummyForL10nScript.js:21
msgid "VUE String with wrapped {parameter}"
msgstr ""

#. TRANSLATORS VUE Fix for https://github.com/nextcloud/docker-ci/pull/663 - Part 1 (src/vue.vue:26)
#: specialVueFakeDummyForL10nScript.js:8
#: specialVueFakeDummyForL10nScript.js:23
msgid "VUE String testing"
msgstr ""

#: specialVueFakeDummyForL10nScript.js:8
#: specialVueFakeDummyForL10nScript.js:23
msgid "VUE String not"
msgstr ""

#. TRANSLATORS src/vue.vue:31
#: specialVueFakeDummyForL10nScript.js:25
msgid "test"
msgstr ""

#. TRANSLATORS VUE Fix for https://github.com/nextcloud/docker-ci/pull/663 - Part 2 (src/vue.vue:29)
#: specialVueFakeDummyForL10nScript.js:10
#: specialVueFakeDummyForL10nScript.js:27
msgid "VUE String with followup double quotes"
msgstr ""

#. TRANSLATORS VUE plural with plain text (src/vue.vue:17)
#: specialVueFakeDummyForL10nScript.js:12
#: specialVueFakeDummyForL10nScript.js:29
msgid "VUE %n Plural"
msgid_plural "VUE %n Plurals"
msgstr[0] ""
msgstr[1] ""

#. TRANSLATORS VUE plural with wrapped parameters (src/vue.vue:21)
#: specialVueFakeDummyForL10nScript.js:16
#: specialVueFakeDummyForL10nScript.js:33
msgid "VUE %n Plural with wrapped %s"
msgid_plural "VUE %n Plurals with wrapped %s"
msgstr[0] ""
msgstr[1] ""

#. TRANSLATORS src/vue.vue:32
#: specialVueFakeDummyForL10nScript.js:35
msgid "one test"
msgid_plural "%n tests"
msgstr[0] ""
msgstr[1] ""

#. TRANSLATORS VUE plural with parameters (src/vue.vue:19)
#: specialVueFakeDummyForL10nScript.js:14
#: specialVueFakeDummyForL10nScript.js:31
msgid "VUE %n Plural with %s"
msgid_plural "VUE %n Plurals with %s"
msgstr[0] ""
Expand Down
20 changes: 20 additions & 0 deletions translations/translationtool/tests/src/vue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,24 @@

<!-- TRANSLATORS VUE Fix for https://github.com/nextcloud/docker-ci/pull/663 - Part 2 -->
{{ t("test", "VUE String with followup double quotes") }}: {{ data["random property"] }}

<button :aria-label="t('test', 'test')">content</button>
<button :aria-label="n('test', 'one test', '%n tests', 6)">content</button>
{{ text }}
</template>

<script>
export default {
computed: {
text() {
// ensure we also handle formats like this
return n(
'forms',
'one string',
'%n strings',
6,
)
}
}
}
</script>
Binary file modified translations/translationtool/translationtool.phar
Binary file not shown.