Skip to content

fix(translationtool): extract every string of a Vue template - #1037

Open
DerDreschner wants to merge 1 commit into
masterfrom
fix/noid/vue-template-extraction
Open

DerDreschner wants to merge 1 commit into
masterfrom
fix/noid/vue-template-extraction

Conversation

@DerDreschner

Copy link
Copy Markdown
Member

Summary

Fixes how the translationtool reads t() and n() in Vue templates, where some strings never reached Transifex. Stacked on #1035, which reworked the same function; the base is feat/noid/lint-source-strings, so the diff only shows the fix.

  • Two strings in one element: each text matched greedily up to the last quote of the line, so in :title="t('app', 'Title')">{{ t('app', 'Label') }} the first match swallowed the second call. xgettext then only warned "unterminated string" about the generated file. Each text now ends at its own closing quote, respecting escapes.
  • Mixed quotes: t('app', "…"), or an n() whose singular and plural use different quotes, matched none of the patterns and was silently dropped. The app ID and each text may now use any kind of quotes, and a text may be literals joined with +. As with xgettext in <script>, comments between the tokens of a call are skipped, and a text ends before a + followed by anything other than a string: 'Hello ' + name gives Hello . Such a fragment can't be translated at runtime; contacts has one, Get from , and the lint reports it when it starts or ends with whitespace.
  • Equal calls on different lines: the hint was looked up by searching for the call's text, which finds the first occurrence, so both calls got the first one's comment and location. Each call now uses its own position.
  • PCRE limits: the new patterns are possessive. Otherwise the comments allowed between tokens exhaust PCRE's backtrack limit, and a text with thousands of escapes or joined parts its JIT stack. A failing pattern now stops the run with the file name instead of dropping strings without a word, because a string that disappears from the POT is removed from Transifex. The generated files are deleted also then, so they don't stay in the app.
  • Hints: a TRANSLATORS comment on the line above or in the rest of the line only reaches the first string of the line, as xgettext does with a comment on the line above and as the developer manual says; later strings on that line get their location like any string without a hint. The location of a call at the start of a line now names that line instead of the one above, and a comment ends at its --> or */ instead of keeping </p> or */" after it.

The calls stay grouped by the quotes of their first text, so the order of existing strings in the POT only changes where a call has another call in its arguments or the old pattern wrote broken code.

Effect on real apps, comparing the POTs of Mail and the server's apps with #1035's tool:

  • 9 strings are extracted that were missing, e.g. Mail's You've sent this message on {date} and Delete {number} thread, dav's Add example event to user's calendar when they first log in, and four in settings.
  • Set reminder for in files_reminders was cut off at its first quote and is now the full Set reminder for '{fileName}'.
  • 163 existing strings get additional location hints, one per occurrence, and 2 get a cleaned-up comment. No string lost its text or a hint, and the order didn't change.
  • The two "unterminated string" warnings are gone.

Left as it is: a template literal with ${…} and the whitespace inside a text are written as before, although they differ from the text at runtime, because changing them would change existing msgids. A comment inside a template expression is assigned by its line, not by its position as xgettext does: a /* TRANSLATORS */ between two calls on a line now reaches the first one, where #1035's greedy pattern happened to give it to the second, and one before a call or inside one is read like a comment on that line. The only TRANSLATORS comments inside template expressions in server and apps-extra, two in files and two in theming, follow their call and reach it. Fixing it changes the lint's comment rules from #1035 too, so it gets its own PR.

Tested with tests/test.sh on xgettext 0.23, 0.26 and 1.0. Each part of the fix is covered by a fixture or test that fails without it. The stop on a failing pattern is tested through the <script> pattern, which fails first; the same check on the other patterns, and check-files deleting its temporary POT when reading it fails, aren't reached by the tests.

Related

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (Claude Code, claude-opus-5-5)

@DerDreschner
DerDreschner added this pull request to stack #1036 November 28, 2026 17:51
@DerDreschner DerDreschner self-assigned this Nov 28, 2026
@DerDreschner
DerDreschner requested a review from susnux November 28, 2026 17:54
@susnux
susnux force-pushed the fix/noid/vue-template-extraction branch from 8402c9d to edb3844 Compare November 29, 2026 19:32
Base automatically changed from feat/noid/lint-source-strings to master December 1, 2026 11:47
@nickvergessen
nickvergessen force-pushed the fix/noid/vue-template-extraction branch from edb3844 to 98dea7d Compare December 1, 2026 11:47
The patterns for t() and n() in Vue templates matched each text
greedily up to the last quote of the line. A second call on a line was
swallowed by the first, which broke the generated file whenever the
text between them wasn't valid JavaScript. t('app', "…") and an n()
whose forms use different quotes matched none of the patterns and were
dropped without any warning. Each text is now a list of string
literals joined with +, each ending at its own closing quote, in any
kind of quotes. Like xgettext, comments may stand between the tokens
of a call, and a text ends before a + followed by anything other than
a string. The quantifiers are possessive, because otherwise the
comments allowed between tokens exhaust PCRE's backtrack limit, and a
text with thousands of escapes or joined parts its JIT stack. A
failing pattern now stops the run instead of dropping strings, also
deleting the generated files that would otherwise stay in the app.

The hint for each call now comes from its own position. Searching for
the call's text found the first occurrence, so two equal calls on
different lines both got the comment and location of the first one. A
TRANSLATORS comment on the line above or in the rest of the line only
reaches the first string of the line, as xgettext does with one on the
line above; the others get their location like any string without a
hint. The location now names the line of the call also when the call
starts a line, and a comment ends at its --> or */ instead of keeping
what follows it.

The calls stay grouped by the quotes of their first text, so the
order of the existing strings in the POT only changes where a call has
another call in its arguments or the old pattern wrote broken code. On
Mail and the server's apps this adds nine strings, completes one that
was cut off at its first quote, and otherwise only adds or cleans up
hints.

Left as they are: a template literal with ${…} and the whitespace
inside a text are written as before, although they differ from the
text at runtime, because changing them would change existing msgids. A
comment inside a template expression is assigned by its line, not by
its position as xgettext does: a TRANSLATORS comment between two calls
on a line now reaches the first one, where the old pattern happened to
give it to the second. Changing that also changes the lint's comment
rules.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
@DerDreschner
DerDreschner force-pushed the fix/noid/vue-template-extraction branch from 98dea7d to ab3d8d0 Compare December 2, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant