WordPress version 6.5 has performance improvements for internationalized (I18N) multilingual translations.

WordPress 6.5 There are a number of internationalization (i18n) improvements in the release that this developer note will focus on.

Localized translation system with improved performance

Over the past year, WordPress contributors have taken a hard look at the performance of existing internationalization (i18n) systems and have ended up creating a system called "Performance Translations" is a new feature plug-in. This plugin provides a thoroughly optimized system that can significantly improve performance. After thousands of Beta testers and a merge announcement late last year, this new library is now included in the WordPress 6.5 in! For all the details, please read#59656 The

Performant Translations The plugin is still very useful and will be continuously maintained to provide unique additional functionality not available in the core solution. Currently, if no PHP file exists, the plugin will automatically include any .mo files to PHP files. This is very helpful for sites whose translations do not come from translate.wordpress.org or only exist on a local server.

This new library lets load binary .mo Files are faster while reducing memory usage. It even supports loading multiple locales at the same time, so site language switching is faster. In addition, it supports translations in PHP files, avoiding the use of binary file formats, and can utilize OPCache caching (if available).

In fact, the new library is so fast that as of WordPress 6.5, in order to merge translations from multiple locales by default, it has become thePreferred Language Functionality Plug-inThe

While this is largely a quiet, backward-compatible change to the bottom line, there are still some things to keep in mind:

renewed.l10n.php Translation file format

When you download language packs from WordPress.org, in addition to your familiar.morespond in singing.poIn addition to the file, you may notice a new file, the.l10n.php. If your.moTranslated documents have corresponding.l10n.phpfile, the system will load the latter, resulting in faster speeds and lower memory consumption.

This is an incremental improvement, so even if there is only one.mofile without the corresponding PHP file, the translation will still load as expected. And vice versa! This means that you could theoretically use just the.l10n.phpTranslated files, and features such as Instant Translation Load will still work as normal. For now, WordPress still requires the appropriate.podocuments and.mofile to perform operations such as update checks. However, this limitation may be resolved in the future, see the#60554Learn more.

treat (to a meal etc)take note of: If you are inwp-content/languagesThe directory does not see any.l10n.phptranslation files, this may be because the language packs have not been updated for some time and therefore no new translations are available.

The following are examples of PHP translation files supported by WordPress 6.5:

图片[1]-WordPress 6.5 版本对国际化(I18N)多语言翻译的性能进行了改进。-光子波动网 | WordPress教程、Elementor教程与故障修复

Note: The EOT here stands for "End of Transmission" character (U+0004or in PHP as“\4”). It is the same separator used in gettext to concatenate contexts with singular strings.

Generate PHP translation files

If you wish to generate these PHP translation files yourself, now Version 4.0 of GlotPressAlready supports the new .l10n.php format, which is a plugin to support translate.wordpress.org.

In addition.WP-CLI 2.10.0(i18n-command 2.6.0) provides a new wp i18n make-php commands, which can be retrieved from the given .po file creates these PHP files. Example:

图片[2]-WordPress 6.5 版本对国际化(I18N)多语言翻译的性能进行了改进。-光子波动网 | WordPress教程、Elementor教程与故障修复

If you are developing a WordPress plugin that handles translations, you can now also use the new WP_Translation_File will .mo file to a PHP file. Example:

图片[3]-WordPress 6.5 版本对国际化(I18N)多语言翻译的性能进行了改进。-光子波动网 | WordPress教程、Elementor教程与故障修复

New filter for customizing this behavior

If you want to disable support for PHP files for some reason, for example, if your project does not yet contain any PHP files and you want to avoid additional file lookups, you can use the new translation_file_format filter to change the preferred format (the default is PHP), examples are shown below:

图片[4]-WordPress 6.5 版本对国际化(I18N)多语言翻译的性能进行了改进。-光子波动网 | WordPress教程、Elementor教程与故障修复

existing load_textdomain_mofile The filter can still be used to filter the path of .mo files to load translations of specific text fields. However, this filter only applies to .mo file. If you need to filter the path to the translated file (either the .l10n.php The file is still .mo file), please use the new load_translation_file Filter.

utilization$l10nglobal variable

In previous versions of WordPress, when loading translations, WordPress would set the MO Instances of the class are stored in the $l10n in global variables. However, in WordPress 6.5, this will be replaced by a new WP_Translations instance of the class instead, which has similar functionality. If your project uses this global variable directly in some way or the MO class, then you need to be concerned about this change.

List of cached language file paths

This is another slight performance improvement, but not related to the new localization libraries described earlier.

In the past, WordPress has been used in get_available_languages(),WP_Textdomain_Registry and other places directly glob() function to retrieve all the .mo file. This is important for loading translations in a timely manner and knowing which translations are installed. However, on sites with a large number of language files, theglob() Operations can become very time consuming.

Therefore, in #58919 / [57287] A new caching mechanism has been introduced in File lookups are now handled centrally in the WP_Textdomain_Registry in the object cache and stores the result in the translations in the group. The format of the cache key is cached_mo_files_which is the MD5 hash of the scanned directory, for example wp-content/languages. The cache is cleared whenever the language pack is updated.

Furthermore, in addition to .l10n.php In addition to files, Find now scans .mo file in case only the former exists on the site.

To learn more, check outOfficial LogThe


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
This article was written by Harry
THE END
If you like it, support it.
kudos0 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments