Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading translations too early #56

Merged
merged 5 commits into from
Nov 28, 2024
Merged

Avoid loading translations too early #56

merged 5 commits into from
Nov 28, 2024

Conversation

Biont
Copy link
Member

@Biont Biont commented Nov 22, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix

What is the current behavior? (You can also link to an open issue here)
WordPress 6.7 removed the need to load_plugin_textdomain manually.
In return, we receive a notice if translations are loaded/accessed too early.

What is the new behavior (if this is a feature change)?

Passing $translate = false in the call to get_plugin_data avoids the _doing_it_wrong and the resulting notice

Since ExecutableModule is responsible for hooking module logic into WordPress, it makes sense to bootstrap the package itself as early as feasible.
Hence, deferring bootstrap to after_setup_thene or init as proposed by core severely limits our flexibility in terms of what modules can to in the "remaining time"

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No.

Other information:

Signed-off-by: Moritz Meißelbach <[email protected]>
@Biont Biont requested a review from gmazzap November 22, 2024 12:27
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.84%. Comparing base (2119d0e) to head (03af2d4).
Report is 2 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #56      +/-   ##
============================================
+ Coverage     98.80%   98.84%   +0.04%     
  Complexity      251      251              
============================================
  Files            10       10              
  Lines           586      607      +21     
============================================
+ Hits            579      600      +21     
  Misses            7        7              
Flag Coverage Δ
unittests 98.84% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Chrico
Copy link
Member

Chrico commented Nov 22, 2024

We should also update the documentation and mention that the data in PluginProperties is not translated (and why). I guess it is also a good opportunity to add a note about the change done in #40 .

@Chrico Chrico self-requested a review November 22, 2024 13:00
Signed-off-by: Moritz Meißelbach <[email protected]>
Signed-off-by: Moritz Meißelbach <[email protected]>
@Biont
Copy link
Member Author

Biont commented Nov 22, 2024

@Chrico Added!

@Chrico
Copy link
Member

Chrico commented Nov 22, 2024

Sorry I need to jump in with another request...first of all: I think this is a breaking change for existing Packages, in case they are using something from the PluginProperties and relying on translated strings.

We should not break the default behavior, but at least fix the _doing_it_wrong()-calls.

In order to stay "backward compatible", we should add a check for the WP version to be < 6.7, to ensure that the current behavior stays as it is. If the current WP version is >= 6.7 and we're calling too early get_plugin_data(), than we should set this to false. I guess something like did_action('after_setup_theme') || current_action('after_setup_theme'); would work here, right?

There are probably some Plugins out there, which are booted late - so after after_setup_theme, like on init. This would not trigger the _doing_it_wrong() and allow to get translated get_plugin_data().

@Biont
Copy link
Member Author

Biont commented Nov 22, 2024

I guess something like did_action('after_setup_theme') || current_action('after_setup_theme'); would work here, right?

Your request makes sense and according to how I understand the situation, this should be a working approach, since it is essentially the same check that WP does before throwing the __doing_it_wrong. I'll make the edit after the weekend

Copy link
Member

@Chrico Chrico left a comment

Choose a reason for hiding this comment

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

As discussed internally, we decided for not auto translating the Plugin Properties. A check by WordPress version and current action/action done would cause an inconsistent result.

We will keep track of this hot topic in WordPress Core and see how we can improve this in future. For now it is always possible to call in code:

esc_html_e( $pluginProperties->description(), $pluginProperties->textDomain() );

when a translated field is required.

@Chrico Chrico merged commit 372a915 into master Nov 28, 2024
64 checks passed
@Chrico Chrico deleted the Biont-patch-1 branch November 28, 2024 09:32
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.

3 participants