Skip to content

Retry just-in-time translation when setting custom path#7713

Closed
swissspidy wants to merge 7 commits intoWordPress:trunkfrom
swissspidy:fix/62337-l10n-jit
Closed

Retry just-in-time translation when setting custom path#7713
swissspidy wants to merge 7 commits intoWordPress:trunkfrom
swissspidy:fix/62337-l10n-jit

Conversation

@swissspidy
Copy link
Member

@swissspidy swissspidy commented Nov 4, 2024

This is a follow-up to https://core.trac.wordpress.org/changeset/59157.

I18N: Retry just-in-time translation when setting custom path.

This is a follow-up to [59127] and [59157], which changed the `load_*_textdomain()` functions to reuse the existing just-in-time translation loading functionality. While this works great for cases where those functions are called too early, it broke cases where they are called after the just-in-time logic already ran.

To solve this, cached entries from the just-in-time logic are reset, so that the loading will be simply reattempted the next time a translation is attempted (e.g. by calling `__()`).

Props swissspidy, peterwilsoncc, twvania.
Fixes #62337.
See #44937

Trac ticket: https://core.trac.wordpress.org/ticket/62337


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Nov 4, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props swissspidy, peterwilsoncc, desrosj, apermo, sergeybiryukov.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Nov 4, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

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

This tests well using the sample theme provided by @t-hamano.

I did a revert of the source changes (since force pushed out of existence) to validate the tests and they fail on trunk as expected.

It would be good to get another set of eyes from either @SergeyBiryukov or @ocean90 as they have a deeper knowledge of the feature.

One nit pick inline

swissspidy and others added 5 commits November 5, 2024 23:47
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
Custom themes/plugins with only en_US files should have their translations loaded as well
Copy link
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

I've given this some good testing today and I'm seeing all of the scenarios described in Trac as resolved with the exception of the most recently raised edge case: My plugin lets users override GlotPress translations with their own custom translation files.

Would also appreciate another review from someone with deeper l10n/i18n knowledge, but I think this one is probably ready.

*/
public function set_custom_path( $domain, $path ) {
// If just-in-time loading was triggered before, reset the entry so it can be tried again.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Copy link

@apermo apermo left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Member

@SergeyBiryukov SergeyBiryukov left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, looks good to me 👍

@desrosj desrosj added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Nov 20, 2024
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Nov 20, 2024
@desrosj
Copy link
Member

desrosj commented Nov 20, 2024

@desrosj desrosj closed this Nov 20, 2024
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.

5 participants