WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#38590 closed defect (bug) (fixed)

Don't use `get_available_languages()` in `_load_textdomain_just_in_time()`

Reported by: ocean90 Owned by: ocean90
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.6
Component: I18N Keywords: has-patch
Focuses: Cc:

Description

get_available_languages() has been introduced in #11774 and is only designed to work with translations for core IMO.

Since [37415] it's also used to retrieve translations in the plugin/theme directory of WP_LANG_DIR.

get_available_languages() does three strpos() checks to prevent returning language codes like admin-zh_TW, continents-cities-zh_TW or ms-zh_TW.
Using get_available_languages() for plugins/themes will not return language codes (see @return tag). It returns the text domain and the language code of a file. But only if a plugin/theme doesn't start with admin- or ms-.

Instead of using get_available_languages() in _load_textdomain_just_in_time() a direct call to glob() should be sufficient.

Attachments (1)

38590.diff (485 bytes) - added by swissspidy 3 years ago.

Download all attachments as: .zip

Change History (4)

@swissspidy
3 years ago

#1 @swissspidy
3 years ago

  • Keywords has-patch added; needs-patch removed

#2 @ocean90
3 years ago

  • Milestone changed from Future Release to 4.7
  • Owner set to ocean90
  • Status changed from new to accepted

We should check the return value of glob() before merging it because glob() returns false in case of a failure.

#3 @ocean90
3 years ago

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

In 39230:

I18N: Don't use get_available_languages() in _load_textdomain_just_in_time().

get_available_languages() is only designed to work with translations for core. Using it for plugins/themes means unnecessary strpos() checks and incomplete results for plugins/themes whose names are beginning with admin- or ms-.

Props swissspidy, ocean90.
Fixes #38590.

Note: See TracTickets for help on using tickets.