Skip to content

Internationalise user-facing strings - #33

Merged
GaryJones merged 1 commit into
developfrom
GaryJones/check-i18n-strings
Aug 20, 2026
Merged

Internationalise user-facing strings#33
GaryJones merged 1 commit into
developfrom
GaryJones/check-i18n-strings

Conversation

@GaryJones

Copy link
Copy Markdown
Contributor

Summary

Most of the plugin's output was already wrapped in translation functions, but a handful of user-facing strings had been left as hard-coded English: the four front-end flagging messages (thank you, invalid nonce, invalid values, already flagged) and the default "Report comment" link text.

None of these could simply be wrapped in __() where they lived. The messages were property defaults and the link text was a method parameter default, and PHP forbids function calls in both. Assigning the messages in the constructor was not an option either, because the plugin is instantiated at load time, before init, and calling __() that early triggers WordPress 6.7's "translation loading triggered too early" notice.

To resolve this, the translatable defaults are now assigned on init via a new set_default_messages() method, which also runs the existing safe_report_comments_* message filters. As a natural consequence those filters now fire on init rather than at construction, which is strictly an improvement: filters added on plugins_loaded or init previously ran too late to take effect. The link text is translated lazily inside get_flagging_link(), which only ever runs well after init.

Test plan

  • With a translation loaded for the safe-report-comments text domain, confirm the report link text and the flagging response messages appear translated.
  • Confirm no "translation loading triggered too early" notice appears with WP_DEBUG enabled on WordPress 6.7+.
  • Confirm the safe_report_comments_*_message and safe_report_comments_flagging_link_text filters still override the defaults.

The front-end flagging messages and the "Report comment" link text were
hard-coded English, so sites could not translate them. Neither could be
wrapped in __() where they lived: PHP forbids function calls in property
and parameter defaults, and assigning them in the constructor would call
__() before init, triggering WordPress 6.7's early-translation notice.

Defaults are now assigned on init via set_default_messages(), which also
runs the existing message filters, and the link text is translated lazily
in get_flagging_link().
@GaryJones GaryJones added this to the Next milestone Aug 20, 2026
@GaryJones
GaryJones merged commit c40b560 into develop Aug 20, 2026
6 checks passed
@GaryJones
GaryJones deleted the GaryJones/check-i18n-strings branch August 20, 2026 00:33
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