Skip to content

feat(translationtool): lint the source strings a pull request adds - #1035

Merged
nickvergessen merged 1 commit into
masterfrom
feat/noid/lint-source-strings
Dec 1, 2026
Merged

nickvergessen merged 1 commit into
masterfrom
feat/noid/lint-source-strings

Conversation

@DerDreschner

@DerDreschner DerDreschner commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

New translationtool.phar lint-source-strings [--base=<checkout>] task, for a per-PR workflow in the org template repository.

Stacked on #1029, which updates gettext/gettext to v5; the base is chore/noid/gettext-v5, so the diff only shows the lint task. Merge it after #1029.

Today, bad source strings are only noticed after the nightly sync has pushed them to Transifex: validateTranslationFiles.sh runs after tx push -s. This task checks the strings before merge, against the translations page of the developer manual.

  • Only new strings: with --base, the base checkout is extracted as well, and only strings missing everywhere in it are checked. Moving a string to another file or app, or moving an app folder, doesn't make it new. Existing strings never block a PR, so apps can adopt the check without cleaning up first.
  • Rules: errors where a string breaks or the manual is explicit, warnings where a rule can't be sure. A string used in several languages, e.g. in PHP and in JavaScript, gets the placeholder rules of each.
    • errors: |, ´/‘/’, ..., any other space than U+00A0 before …, leading/trailing whitespace (not in the info.xml texts, which aren't joined in code), contractions (don't, you're, can not), id/ids (not in URLs), HTML markup, plurals without any placeholder, %n inside a placeholder like %name%, a TRANSLATORS comment on the line of a Vue template string that the extraction also gives to the next line's string
    • errors in PHP strings: %n outside n(), more than one placeholder without a position, or unpositioned mixed with positioned ones; a single % that doesn't start a placeholder (PHP always runs vsprintf(), so only %% shows a percent sign). Navigation names in info.xml count as PHP strings. Its name, summary and description aren't formatted at all, so no placeholder rule applies to them.
    • errors in JavaScript and Vue strings: %s/%1$s, {{name}} or { name }, because only {name} and %n are replaced there
    • errors in Python strings: %n, and more than one %s without a name (Python can't reorder them, %(name)s can be)
    • warnings: "user" and "admin(istrator)" (not "user interface" or "user agent"), %n in only one plural form, a plural that shows its count with another placeholder than %n, %n in a JavaScript t() (only replaced when a count is passed), a number placeholder (%d, {count}, {seconds} …) outside a plural, placeholders named like {0}, a colon or another translation joined to a translation outside the string, a string sharing its line with a string whose TRANSLATORS comment only reaches the first one, a comment that addresses translators without starting with TRANSLATORS, a string that gets a TRANSLATORS comment meant for the string above it (the POT shows the comment, and in the source it follows the end of a translation call, so xgettext gave it to the next string). That last one is reported once: on the string that gets the comment if it is new, otherwise on the string the comment follows. It reads the source with patterns, so it's a warning, not an error.
  • Locations: findings name the source file and line, also for Vue <script> sections and info.xml; a finding about one occurrence of a repeated string names that occurrence. With --format=github they are printed as annotations. The POT stays the same for existing strings; expected.pot only changes because the new test fixtures add strings.

It also fixes a crash of create-pot-files, and so of the nightly sync, for a Vue file whose <template> starts on line 1 (getTranslatorHintWithVueSource() read the line before the first one).

Tested with tests/test.sh on PHP 8.3 and 8.5, with xgettext 0.23 (as in this repository's CI), 0.26 and 1.0, and against Nextcloud Mail:

  • A PR adding t('mail', 'Checking the signature...') in a <script> gets one annotation on the right line of ThreadEnvelope.vue.
  • All of Mail's strings give 7 errors and 55 warnings, all real: for example t('mail', 'Sender') + ': ' + from.email and {{ t('mail', 'Redirect URI') }}:.

Follow-ups (not in this PR)

Found along the way. They change the POT, so they get their own pull requests.

Fixed in a stacked pull request:

  • fix(translationtool): extract every string of a Vue template #1037
    • Vue templates: on a line like <NcButton :title="t('app', 'Title')">{{ t('app', 'Label') }}</NcButton>, only the first string reaches the POT, xgettext just warns "unterminated string" about the generated file.
    • Vue templates: t('app', "…") with the app ID in single and the text in double quotes isn't extracted at all, without any warning. Mail has one: You've sent this message on {date} in ThreadEnvelope.vue.
    • Vue templates: a TRANSLATORS comment above a later occurrence of a repeated string doesn't reach the POT, because getTranslatorHintWithVueSource() finds the first occurrence by its text.

Still open:

  • Vue templates: a comment inside a template expression is assigned by its line, not by its position as xgettext does, e.g. a /* TRANSLATORS */ between two calls on a line reaches the first one. Fixing it changes this PR's comment rules too.

Next steps:

  • Write the real .vue file names into the POT instead of the generated file's.
  • The manual could say that xgettext drops a TRANSLATORS comment above t( when the string is on a later line, it has to be directly above the string.
  • The comment warnings read the source with patterns, so unusual layouts slip through. A second xgettext run with all comments (--add-comments without a tag) would make them exact.
  • Let validateTranslationFiles.sh use these rules. The nightly sync needs a way to run only the existing ones, or it would flood every app.

Related

#1028 makes the extraction about 17× faster, so a PR check with --base takes about 1 s instead of 20 s. Both PRs change createOrCheckPotFile(), so the second one to merge needs a small rebase and a rebuilt phar.

Order: #1029, this PR, then publish the image ("Docker Publish" with translations), then the template PR, because the template workflow runs the task in continuous-integration-translations:latest.

🤖 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 13:32
@DerDreschner DerDreschner self-assigned this Nov 28, 2026
@DerDreschner
DerDreschner force-pushed the feat/noid/lint-source-strings branch from 79666df to 351670e Compare November 28, 2026 13:45
DerDreschner added a commit to nextcloud/mail that referenced this pull request Nov 28, 2026
Agents didn't follow the translation guidelines for new strings, and
nothing in the code states the rules for the English text. The section
now links the guidelines and adds the one rule no lint can check: a
TRANSLATORS comment for an ambiguous string. The mechanical rules are
left to the lint-source-strings check from nextcloud/docker-ci#1035.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
Base automatically changed from chore/noid/gettext-v5 to master November 29, 2026 19:32
The nightly sync pushes source strings to Transifex before
validateTranslationFiles.sh checks them, so strings against the
translation guidelines reach translators before anything complains.
lint-source-strings checks an app's source strings against the
translations page of the developer manual, so a workflow can catch
them before merge. Rules are errors where a string breaks at runtime
or the manual is explicit, and warnings where they can't be sure.
With --base=<checkout> it extracts the base checkout too and only
checks strings missing there, so existing strings never block a pull
request.

Findings name the source file and line, as plain text or, with
--format=github, as annotations. Strings from Vue files and info.xml are
extracted through generated files, so these now record which source
line each of their lines came from. That also covers Vue <script>
sections, whose strings had no source reference at all. The POT
output is unchanged.

It also stops create-pot-files from crashing on a Vue file whose
<template> starts on line 1, which the lint job would hit on every
pull request of such an app.

Left for follow-ups: writing real .vue references into the POT, and
letting validateTranslationFiles.sh use these rules, which needs a way
to run only the existing ones in the nightly sync. Faster extraction
is in a separate pull request.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
@susnux
susnux force-pushed the feat/noid/lint-source-strings branch from 351670e to 3023348 Compare November 29, 2026 19:32

@nickvergessen nickvergessen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI reported some false positive warnings would be possible. But they just indicate bad translation strings never the less, so sounds good.

@nickvergessen
nickvergessen merged commit 2e42e9b into master Dec 1, 2026
3 checks passed
@nickvergessen
nickvergessen deleted the feat/noid/lint-source-strings branch December 1, 2026 11:47
rotdrop pushed a commit to rotdrop/nextcloud-app-mail that referenced this pull request Dec 1, 2026
Agents didn't follow the translation guidelines for new strings, and
nothing in the code states the rules for the English text. The section
now links the guidelines and adds the one rule no lint can check: a
TRANSLATORS comment for an ambiguous string. The mechanical rules are
left to the lint-source-strings check from nextcloud/docker-ci#1035.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
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.

2 participants