Skip to content

Stop writing every label's wording twice - #189

Merged
JE-Chen merged 2 commits into
mainfrom
fix/retranslate-duplication
Jul 26, 2026
Merged

Stop writing every label's wording twice#189
JE-Chen merged 2 commits into
mainfrom
fix/retranslate-duplication

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Cleanup of the mechanical conversion in #188. Sonar raised 45 findings on it and both kinds were fair.

What was wrong

The generated shape put each string in two places:

self.hint_label = QLabel(_t("signage_hint", "Presets are saved from the Presets menu. …"))
retranslator.bind(self.hint_label, "signage_hint", "Presets are saved from the Presets menu. …")
  • 35 × S1192 — the wording duplicated, so the long hints appeared twice in the file. Change one, and the other silently disagrees.
  • 10 × S5799 — my script flattened multi-line fallbacks onto a single line as "a " "b" "c", which reads like a missing comma.

The fix

bind() now sets the text as well as recording the key — it already computed the string, it just wasn't applying it. So the widget is built empty and the wording is written once, keeping its original multi-line shape:

self.hint_label = QLabel()
retranslator.bind(self.hint_label, "signage_hint",
                  "Presets are saved from the Presets menu. The rotation wraps at the end, so a "
                  "machine left running keeps cycling.")

236 widgets converted, 7 now-unused imports removed, and the flattened one-liners are gone (0 remain).

Verified

Switching still works exactly as before: all seven languages in sequence and back to English, 0 strings left in the previous language each time, whiteboard still open, page state byte-identical.

858 passed, pyflakes silent.

Note on sequencing

I merged #188 while these 45 were outstanding — the quality gate passed, so the checks were green, but green gate is not the same as no findings, and I should have read them first. Doing that here instead.

The mechanical pass left each string in two places - once in the constructor
and once in the registration - so the long hint sentences appeared twice in the
file, and flattening the multi-line ones onto a single line read like a missing
comma. Sonar flagged 45 of those, and it was right on both counts.

bind() now sets the text as well as recording the key, so the widget is built
empty and the wording is written once, in its original multi-line shape.
@codacy-production

codacy-production Bot commented Jul 26, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -12 duplication

Metric Results
Complexity 0
Duplication -12

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Building the widget and registering it were two lines of identical shape
repeated 236 times, and Sonar's duplication check called it at 7.3 percent
against a 3 percent gate - fairly, since that is what boilerplate is.

tr() sets the text, registers the key and hands the widget back, so it reads as
one assignment:

    self.hint_label = tr(QLabel(), "signage_hint", "Presets are saved from ...")

The longer sentences keep their line breaks rather than being flattened into a
single over-long implicit concatenation.
@sonarqubecloud

Copy link
Copy Markdown

@JE-Chen
JE-Chen merged commit ebe3f8f into main Jul 26, 2026
5 checks passed
@JE-Chen
JE-Chen deleted the fix/retranslate-duplication branch July 26, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant