Making WordPress.org

Changeset 10091


Ignore:
Timestamp:
07/23/2020 04:01:51 AM (6 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 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!
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

    r9118 r10091  
    3535                'blocks'            => false,
    3636                'block_assets'      => false,
     37                'language_pack'     => false,
    3738        );
    3839
    … …  
    5455                'tags'              => true,
    5556                'tested'            => true,
     57                'language_pack'     => false,
    5658                'blocks'            => false,
    5759                'block_assets'      => false,
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r9768 r10091  
    178178                                }
    179179                        }
     180                }
     181
     182                // Only include language packs for the requested locale.
     183                if ( ! empty( $fields['language_pack'] ) ) {
     184                        $response['language_pack'] = array_values( array_filter( $response['language_pack'], function( $item ) use ( $request ) {
     185                                return ( $request->locale === $item['language'] );
     186                        } ) );
    180187                }
    181188
Note: See TracChangeset for help on using the changeset viewer.