Make WordPress Core


Ignore:
Timestamp:
04/30/2024 08:37:25 AM (2 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-language-pack-upgrader.php

    r57381 r58062  
    333333                $files = $wp_filesystem->dirlist( $remote_source );
    334334
    335                 // Check to see if a .po and .mo exist in the folder.
    336                 $po = false;
    337                 $mo = false;
     335                // Check to see if the expected files exist in the folder.
     336                $po  = false;
     337                $mo  = false;
     338                $php = false;
    338339                foreach ( (array) $files as $file => $filedata ) {
    339340                        if ( str_ends_with( $file, '.po' ) ) {
     
    341342                        } elseif ( str_ends_with( $file, '.mo' ) ) {
    342343                                $mo = true;
    343                         }
     344                        } elseif ( str_ends_with( $file, '.l10n.php' ) ) {
     345                                $php = true;
     346                        }
     347                }
     348
     349                if ( $php ) {
     350                        return $source;
    344351                }
    345352
     
    349356                                $this->strings['incompatible_archive'],
    350357                                sprintf(
    351                                         /* translators: 1: .po, 2: .mo */
    352                                         __( 'The language pack is missing either the %1$s or %2$s files.' ),
     358                                        /* translators: 1: .po, 2: .mo, 3: .l10n.php */
     359                                        __( 'The language pack is missing either the %1$s, %2$s, or %3$s files.' ),
    353360                                        '<code>.po</code>',
    354                                         '<code>.mo</code>'
     361                                        '<code>.mo</code>',
     362                                        '<code>.l10n.php</code>'
    355363                                )
    356364                        );
Note: See TracChangeset for help on using the changeset viewer.