Making WordPress.org


Ignore:
Timestamp:
07/23/2020 04:01:51 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Allow the plugin_information endpoint to return the language pack for the requested locale.

This will allow for a WordPress to install the translations for a plugin at the same time as a plugin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r9827 r10091  
    224224        // Fun fact: ratings are stored as 1-5 in postmeta, but returned as percentages by the API
    225225        $result['author_block_rating'] = get_post_meta( $post_id, 'author_block_rating', true ) ? 20 * get_post_meta( $post_id, 'author_block_rating', true ) : $result['rating'];
     226
     227        // Translations.
     228        $result['language_pack'] = [];
     229        if ( defined ( 'API_WPORGPATH' ) && file_exists( API_WPORGPATH . '/translations/lib.php' ) ) {
     230            require API_WPORGPATH . '/translations/lib.php';
     231
     232            $result['language_pack'] = find_all_translations_for_type_and_domain(
     233                'plugin',
     234                $result['slug'],
     235                $result['version']
     236            );
     237            $result['language_pack'] = array_map( function( $item ) use ( $result ) {
     238                return [
     239                    'type'     => 'plugin',
     240                    'slug'     => $result['slug'],
     241                    'language' => $item->language,
     242                    'version'  => $item->version,
     243                    'updated'  => $item->updated,
     244                    'package'  => $item->package,
     245                ];
     246            }, $result['language_pack'] );
     247        }
    226248
    227249        // That's all folks!
Note: See TracChangeset for help on using the changeset viewer.