Skip to content

Guard against hardcoded ConfigEntry strings#4304

Merged
marcelveldt merged 4 commits into
devfrom
i18n-config-entry-label-check
Jun 18, 2026
Merged

Guard against hardcoded ConfigEntry strings#4304
marcelveldt merged 4 commits into
devfrom
i18n-config-entry-label-check

Conversation

@marcelveldt

@marcelveldt marcelveldt commented Jun 17, 2026

Copy link
Copy Markdown
Member

What does this implement/fix?

A ConfigEntry's label/description are localized at serialization from strings.json (via the config_entries.<key> key), so passing them as literals in code — like in #4180 — means they never reach Lokalise and stay English-only. There was nothing stopping a contributor from doing that.

This adds a pre-commit/CI guard that flags hardcoded ConfigEntry text, and migrates every existing offender into strings.json.

  • scripts/check_config_entries.py: a pre-commit hook (runs in CI via the lint job) that fails when a ConfigEntry passes a hardcoded label/description/action_label — both plain string literals and f-strings. Skips _*/test template providers.
  • Static literal labels moved to strings.json: bbc_sounds, amplipi (new strings.json), squeezelite, and the shared scrobbler entries → common (used by 3 scrobble providers).
  • Dynamic f-string labels moved to strings.json templates ({0}/{1}) + translation_params: the airplay pairing flow, ard_audiothek sign-in label, lastfm_scrobble save reminder + authorize action, yandex_music base URL description, and the yandex_smarthome direct-HTTPS warning.
  • Dynamic keys (squeezelite per-preset, the airplay pairing actions) use an explicit translation_key so they share one template.
  • Regenerated en.json.

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.

A ConfigEntry's label/description must be authored in strings.json (resolved via
config_entries.<key>) so they reach Lokalise; passing them as literals in code
leaves them English-only. Adds a pre-commit/CI guard and moves the existing
literal labels into strings.json.

- scripts/check_config_entries.py: hook flagging literal label/description/
  action_label on a ConfigEntry (skips _*/test templates; f-strings out of scope)
- bbc_sounds / amplipi / squeezelite: move labels & descriptions to strings.json
- scrobbler shared entries -> common strings.json (used by 3 scrobble providers)
- squeezelite preset uses translation_key + translation_params (dynamic key)
- regenerated en.json
Copilot AI review requested due to automatic review settings June 17, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents contributors from hardcoding user-facing ConfigEntry text (which would bypass Lokalise) by adding a pre-commit/CI guard, and migrates existing literal ConfigEntry labels/descriptions into the appropriate strings.json files (including common), with regenerated en.json.

Changes:

  • Added scripts/check_config_entries.py and a pre-commit hook to fail on string-literal ConfigEntry label/description/action_label.
  • Migrated hardcoded ConfigEntry strings in several providers/helpers into strings.json (and updated code to rely on translations).
  • Updated squeezelite preset entries to use translation_key + translation_params, and regenerated music_assistant/translations/en.json.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/check_config_entries.py New AST-based guard to detect hardcoded ConfigEntry user-facing strings.
.pre-commit-config.yaml Registers the new check_config_entries hook for pre-commit/CI linting.
music_assistant/strings.json Adds new common/shared config_entries translation source strings.
music_assistant/translations/en.json Regenerated English translation bundle reflecting new/updated source strings.
music_assistant/helpers/scrobbler.py Removes literal ConfigEntry text so shared scrobble entries resolve via translations.
music_assistant/providers/squeezelite/player.py Switches dynamic preset label/description to translation_key + params.
music_assistant/providers/squeezelite/strings.json Adds translatable template strings for presets.
music_assistant/providers/bbc_sounds/init.py Removes hardcoded ConfigEntry labels to rely on translations.
music_assistant/providers/bbc_sounds/strings.json Adds missing config_entries strings for the migrated BBC Sounds entries.
music_assistant/providers/amplipi/init.py Removes hardcoded ConfigEntry label/description to rely on translations.
music_assistant/providers/amplipi/strings.json New provider strings.json containing the migrated AmpliPi config entry strings.

Comment thread music_assistant/strings.json Outdated
Comment thread music_assistant/translations/en.json Outdated
Extends the guard to f-strings and moves the dynamic labels/descriptions into
strings.json templates ({0}/{1}) + translation_params, so transient auth/status
text localizes too instead of being interpolated in code.

- check_config_entries now also flags f-string label/description/action_label
- airplay pairing flow (6), ard_audiothek sign-in label, lastfm_scrobble save
  reminder + authorize action, yandex_music base_url description, and the
  yandex_smarthome direct-HTTPS warning -> translation_params + strings.json
- regenerated en.json
Copilot AI review requested due to automatic review settings June 17, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Comment thread scripts/check_config_entries.py
Comment thread music_assistant/strings.json Outdated
@marcelveldt marcelveldt merged commit 5e87e57 into dev Jun 18, 2026
9 checks passed
@marcelveldt marcelveldt deleted the i18n-config-entry-label-check branch June 18, 2026 06:11
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