Make WordPress Core

Opened 8 months ago

Closed 5 months ago

Last modified 5 months ago

#60554 closed enhancement (fixed)

Add support for using only PHP translation files

Reported by: swissspidy's profile swissspidy Owned by: swissspidy's profile swissspidy
Milestone: 6.6 Priority: normal
Severity: normal Version: 6.5
Component: I18N Keywords: has-patch has-unit-tests commit needs-dev-note
Focuses: Cc:

Description (last modified by swissspidy)

In WordPress 6.5 we're adding support for PHP translation files. They still require accompanying .mo and .po files. However, it doesn't have to be this way!

It should be possible for projects (plugins, themes, and core) to only use .l10n.php files.

A few areas that would need changing:

wp_get_installed_translations()

wp_get_installed_translations() is used for getting the list of installed translations for plugins/themes/core when updating language packs and also when uninstalling plugins/themes (to remove the translations again).

Language_Pack_Upgrader

\Language_Pack_Upgrader::check_package() checks whether there are .mo and .po in the language pack. It should also support language packs with only a .l10n.php file.

load_textdomain() / load_default_textdomain()

Not sure about this one.

Right now you can pass an .mo file path, even though the file doesn't exist, and WordPress will load the .l10n.php counterpart. So technically no change is required. However, what if you want to directly pass an .l10n.php file path instead?

Change History (7)

#1 @swissspidy
8 months ago

  • Description modified (diff)

This ticket was mentioned in PR #6129 on WordPress/wordpress-develop by @swissspidy.


8 months ago
#2

  • Keywords has-patch has-unit-tests added
  1. Scan for PHP files in wp_get_installed_translations(). So if only a PHP translation file exists, updates still work as expected. Also has the benefit of using $wp_textdomain_registry->get_language_files_from_path() instead of scandir, so the initial file list is cached.
  2. Support language packs that contain only PHP translation files but no mo/po.

Trac ticket: https://core.trac.wordpress.org/ticket/60554

#3 @swissspidy
5 months ago

  • Keywords commit added

#4 @swissspidy
5 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58061:

I18N: Improve support for using only PHP translation files.

This builds on top of the PHP translation file support added in WordPress 6.5, improving the behavior for projects using solely .l10n.php translation files and no .mo. and .po files.

Updates wp_get_installed_translations(), which is used when updating language packs and when uninstalling plugins/themes (to remove the translations again), to look for PHP translation files and read metadata from them. Additionally, the file lookup is now cached thanks to using WP_Textdomain_Registry.

Updates Language_Pack_Upgrader::check_package() to allow language packs that only contain PHP translation files. While WordPress.org continues to serve .mo and .po files, third-party services might want to only use the PHP file format.

Props swissspidy.
Fixes #60554.

#5 @swissspidy
5 months ago

  • Keywords needs-dev-note added

This can be added to the general i18n dev-note for 6.6.

#6 @swissspidy
5 months ago

In 58062:

I18N: Actually add all the files for [58061], not just the test fixtures.

Improve support for using only PHP translation files.

This builds on top of the PHP translation file support added in WordPress 6.5, improving the behavior for projects using solely .l10n.php translation files and no .mo. and .po files.

Updates wp_get_installed_translations(), which is used when updating language packs and when uninstalling plugins/themes (to remove the translations again), to look for PHP translation files and read metadata from them. Additionally, the file lookup is now cached thanks to using WP_Textdomain_Registry.

Updates Language_Pack_Upgrader::check_package() to allow language packs that only contain PHP translation files. While WordPress.org continues to serve .mo and .po files, third-party services might want to only use the PHP file format.

See #60554.

Note: See TracTickets for help on using tickets.