Skip to content

Fix unreplaced placeholders in console messages#123

Open
JumpLink wants to merge 1 commit into
mainfrom
fix/118-message-format-placeholders
Open

Fix unreplaced placeholders in console messages#123
JumpLink wants to merge 1 commit into
mainfrom
fix/118-message-format-placeholders

Conversation

@JumpLink

Copy link
Copy Markdown
Owner

Fixes #118

Problem

The message console showed Found $d labels. with a literal $d in every language. The labels module dispatched messages with three inconsistent placeholder styles:

Message Placeholder Result
Found $d labels. $d shown literally — no formatter knows $d
Label already defined at line %s: %d %s/%d swapped line number formatted as %s, line content as %d (→ NaN)
Label {label} is already used as a symbol… {label} shown literally

On top of that, only the GNOME app formatted params at all (via gettext + GJS String.format); the Web and Android apps logged the raw message, so even %d placeholders were never substituted there.

Fix

  • Core: unify all message placeholders to printf-style %s/%d (the style every other core message already uses) and fix the swapped specifier order in the "Label already defined" message.
  • Core: add a small platform-independent formatMessage() utility.
  • Web: substitute params via formatMessage() in all console log handlers.
  • Android: translate and format console messages via localize() from @nativescript/localize (which substitutes printf-style params via vsprintf), with a safe fallback to the raw message. Console messages were previously shown untranslated.
  • GNOME: no code change needed — gettext + String.format handles %s/%d correctly once the msgids are fixed.
  • Translations: migrate msgids and msgstrs in all 15 .po files and the .pot, preserving every existing translation. The German .po had already worked around the bug with %d in its msgstrs; that was kept intact. Android i18n JSONs and the .pot were regenerated with yarn workspace @learn6502/translations run build.

Verification

  • formatMessage() checked against all affected messages (singular/plural count, line-number+content, label name, %% escape, no-params passthrough).
  • GNOME path smoke-tested in GJS: "Found %d labels.".format(5)Found 5 labels.
  • Placeholder consistency of all migrated .po entries validated by script (each msgstr contains exactly the placeholders of its msgid).
  • yarn format, yarn check:format, yarn build pass; type checks pass for 6502, common-ui, app-web, app-android.

The labels module dispatched messages with three inconsistent
placeholder styles ($d, {label}, and %s/%d in swapped order), so
"Found $d labels." was shown literally on every platform (#118).

- Core: unify all message placeholders to printf-style %s/%d and
  fix the swapped params order in "Label already defined at line"
- Core: add formatMessage() utility for platforms without their
  own gettext formatting
- Web: substitute message params via formatMessage()
- Android: translate and format console messages via localize()
- Translations: migrate msgids/msgstrs to the corrected
  placeholders, preserving all existing translations

Fixes #118
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.

$d is not replaced in "Found $d labels."

1 participant