
WordPress 6.5 added support for PHP translation files which are known to make localization blazing fast. Starting WordPress 6.5, If an .mo
translation file has a corresponding .l10n.php
file, the PHP translation file will be used making things faster and even use less memory. Other benefit is PHP translation can leverage OPCache if available which isn’t the case with the binary format.
If you only have .mo
translation file, WordPress still loads it.
You can use the Permormat Translations plugin to automatically convert .mo
to it’s corresponding .l10n.php
. It’s the feature plugin which is actually merged into WordPress 6.5. With that said, the plugin is still useful.
Creating PHP Translation files
In cases where your plugins or themes are not hosted in WordPress.org repository, you’ll still need to create .l10n.php
files. WP-CLI 2.10.0 has a command
# Create PHP files for all PO files in the languages directory.
$ wp i18n make-php languages
Are you a command line freak? Check out my favourite WP CLI commands .
Disable PHP Translation files
If you want to disable this feature in WordPress 6.5 altogether, you can use the following code snippet. It helps prevent the extra file lookup operation. Now that .php is the new default, we revert it back to .mo
add_filter(
'translation_file_format',
static function () {
return 'mo';
}
);