Make WordPress Core


Ignore:
Timestamp:
01/23/2024 01:32:34 PM (8 months ago)
Author:
swissspidy
Message:

I18N: Introduce a more performant localization library.

This introduces a more lightweight library for loading .mo translation files which offers increased speed and lower memory usage.
It also supports loading multiple locales at the same time, which makes locale switching faster too.

For plugins interacting with the $l10n global variable in core, a shim is added to retain backward compatibility with the existing pomo library.

In addition to that, this library supports translations contained in PHP files, avoiding a binary file format and leveraging OPCache if available.
If an .mo translation file has a corresponding .l10n.php file, the latter will be loaded instead.
This behavior can be adjusted using the new translation_file_format and load_translation_file filters.

PHP translation files will be typically created by downloading language packs, but can also be generated by plugins.
See https://make.wordpress.org/core/2023/11/08/merging-performant-translations-into-core/ for more context.

Props dd32, swissspidy, flixos90, joemcgill, westonruter, akirk, SergeyBiryukov.
Fixes #59656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php

    r55865 r57337  
    2121     */
    2222    protected static $user_id;
     23
     24    /**
     25     * @var WP_Locale_Switcher
     26     */
     27    protected $orig_instance;
    2328
    2429    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     
    4348        $wp_textdomain_registry = new WP_Textdomain_Registry();
    4449
    45         remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) );
     50        $this->orig_instance = $wp_locale_switcher;
     51
     52        remove_all_filters( 'locale' );
     53        remove_all_filters( 'determine_locale' );
     54
    4655        $wp_locale_switcher = new WP_Locale_Switcher();
    4756        $wp_locale_switcher->init();
     
    5968        restore_current_locale();
    6069
    61         remove_filter( 'locale', array( $wp_locale_switcher, 'filter_locale' ) );
    62         $wp_locale_switcher = new WP_Locale_Switcher();
    63         $wp_locale_switcher->init();
     70        remove_all_filters( 'locale' );
     71        remove_all_filters( 'determine_locale' );
     72
     73        $wp_locale_switcher = $this->orig_instance;
     74
     75        unload_textdomain( 'internationalized-plugin' );
     76        unload_textdomain( 'custom-internationalized-theme' );
    6477
    6578        parent::tear_down();
Note: See TracChangeset for help on using the changeset viewer.