Internationalise user-facing strings - #33
Merged
Merged
Conversation
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, beforeinit, 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
initvia a newset_default_messages()method, which also runs the existingsafe_report_comments_*message filters. As a natural consequence those filters now fire oninitrather than at construction, which is strictly an improvement: filters added onplugins_loadedorinitpreviously ran too late to take effect. The link text is translated lazily insideget_flagging_link(), which only ever runs well afterinit.Test plan
safe-report-commentstext domain, confirm the report link text and the flagging response messages appear translated.WP_DEBUGenabled on WordPress 6.7+.safe_report_comments_*_messageandsafe_report_comments_flagging_link_textfilters still override the defaults.