Make WordPress Core

Opened 22 months ago

Closed 19 months ago

Last modified 18 months ago

#58035 closed enhancement (fixed)

Allow to short-circuit load_textdomain()

Reported by: ocean90's profile ocean90 Owned by: ocean90's profile ocean90
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-unit-tests commit needs-dev-note add-to-field-guide
Focuses: Cc:

Description

load_textdomain() has a filter override_load_textdomain which only allows to return true to prevent further execution of the function.

This becomes an issue if the filter callback was not able to load the file. Returning true in this case is not an option because that will cause _load_textdomain_just_in_time() to return early and not falling back to translations provided by a theme/plugin. Returning false means that load_textdomain() does all the work again even we already know that the file doesn't exist.

For this I'm proposing a pre_load_textdomain filter which runs before the current override_load_textdomain filter. This will be consistent with the pre_load_script_translations filter in load_script_translations() for JavaScript translations.

The filter will be useful to plugins which can develop and test alternative loading/caching strategies for translations.

Change History (6)

This ticket was mentioned in PR #4227 on WordPress/wordpress-develop by @ocean90.


22 months ago
#1

  • Keywords has-patch has-unit-tests added

#2 @spacedmonkey
19 months ago

  • Keywords commit added
  • Owner set to ocean90
  • Status changed from new to assigned

@ocean90 @swissspidy Marking this ready for commit.

#3 @swissspidy
19 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 55928:

I18N: Allow to short-circuit load_textdomain().

Introduces a new pre_load_textdomain filter, which is useful for plugins to develop and test alternative loading/caching strategies for translations. This brings consistency with the existing pre_load_script_translations filter for JavaScript translations.

Props ocean90, swissspidy.
Fixes #58035.

#5 @swissspidy
18 months ago

  • Keywords needs-dev-note added

#6 @stevenlinx
18 months ago

  • Keywords add-to-field-guide added
Note: See TracTickets for help on using tickets.