Make WordPress Core


Ignore:
Timestamp:
01/15/2024 07:03:27 PM (2 years ago)
Author:
swissspidy
Message:

I18N: Cache list of language file paths in WP_Textdomain_Registry.

Loading a list of language file paths using glob() can be expensive if involving thousands of files.

Expands scope of WP_Textdomain_Registry to cache list of language file paths in object cache and provides a way to invalidate that cache upon translation updates. Plugins can clear the cache using calls such as wp_cache_delete( 'cached_mo_files_' . md5( $path ), 'translations' );

Props mreishus, swissspidy
Fixes #58919

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r57286 r57287  
    13991399 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
    14001400 *
     1401 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
     1402 *
    14011403 * @param string $dir A directory to search for language files.
    14021404 *                    Default WP_LANG_DIR.
     
    14051407 */
    14061408function get_available_languages( $dir = null ) {
     1409    global $wp_textdomain_registry;
     1410
    14071411    $languages = array();
    14081412
    1409     $lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' );
     1413    $path       = is_null( $dir ) ? WP_LANG_DIR : $dir;
     1414    $lang_files = $wp_textdomain_registry->get_language_files_from_path( $path );
     1415
    14101416    if ( $lang_files ) {
    14111417        foreach ( $lang_files as $lang_file ) {
Note: See TracChangeset for help on using the changeset viewer.