A faster load_textdomain
Author: | Per Soderlind (profile at wordpress.org) |
WordPress version required: | 5.9 |
WordPress version tested: | 6.4.3 |
Plugin version: | 2.3.0 |
Added to WordPress repository: | 06-11-2023 |
Last updated: | 27-02-2024 |
Rating, %: | 0 |
Rated by: | 0 |
Plugin URI: | https://github.com/soderlind/a-faster-load-te... |
Total downloads: | 1 831 |
Active installs: | 70+ |
Click to start download |
NOTE This plugin is not needed if you are running WordPress 6.5 or later, as the functionality is built into WordPress core. If you need to generate translation in the new
.l10n.php
format, use the Performant Translations plugin instead.
This is a WordPress plugin that caches the .mo file as an PHP array, and include the array instead of the .mo file.
In theory, nothing is faster in PHP than loading and executing another PHP file.
How it works
If you have a plugin or theme that loads a textdomain, e.g. load_textdomain( 'textdomain', $path_to_mo_file )
, then this plugin will:
- Look for a PHP version of the .mo file in
WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'
directory. - If the PHP version exists, include the file.
- If the PHP version doesn’t exist, load the .mo file, and save the file as an PHP array in
wp-content/cache/a-faster-load-textdomain/
directory.
The localized PHP array can be cached via PHP OPcache. If you have PHP OPcache enabled, then the localized PHP array will be cached in memory, and the PHP file will not be parsed again.
Filters
a_faster_load_textdomain_cache_path
Change the cache path, default is WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'
.
add_filter( 'a_faster_load_textdomain_cache_path', function( $path ) {
return WP_CONTENT_DIR . '/cache/my-cache';
} );
GitHub
The plugin source is available at GitHub
ChangeLog