內容簡介
- 這是一個WordPress外掛,將.mo檔案作為PHP數組進行緩存,並將該數組包含在.mo檔案中。
- 理論上,在PHP中沒有什麼比加載和執行另一個PHP文件更快的了。
- 如果您使用的外掛或佈景主題加載了文字域,例如load_textdomain('textdomain',$path_to_mo_file),則此外掛將:
1. 在WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'目錄中尋找.mo文件的PHP版本。
2. 如果存在PHP版本,則包含該文件。
3. 如果不存在PHP版本,則加載.mo文件並將該文件保存為PHP數組在wp-content/cache/a-faster-load-textdomain/目錄中。
- 可以通過PHP OPcache緩存本地化的PHP數組。如果您已啟用了PHP OPcache,則本地化的PHP數組將被緩存在內存中,PHP文件就不會再被解析。
外掛標籤
開發者團隊
原文外掛簡介
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
