Making WordPress.org

Changeset 12176


Ignore:
Timestamp:
11/01/2022 06:41:55 AM (4 years ago)
Author:
dd32
Message:

Translate: Ensure that /api/projects/wp-plugins/{$plugin}/dev/ returns translation sets with appropriate wp_locale fields.

Currently GlotPress doesn't support locale variants, resulting in API endpoints returning multiple sets with the same wp_locale value. This fixes that.

This will result in the plugin directory correctly listing hreflang tags, as it'll no longer list variants as their base locale.

Fixes #4367.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
2 edited

Legend:

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

    r10447 r12176  
    461461                $translation_sets = $this->cache_get( $post->post_name, $branch, $cache_suffix );
    462462                if ( false === $translation_sets ) {
    463                         $api_url  = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $post->post_name . '/' . $branch, [ 'https' ] );
     463                        $api_url  = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $post->post_name . '/' . $branch . '/', [ 'https' ] );
    464464                        $response = wp_remote_get( $api_url );
    465465
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r12123 r12176  
    7777                //Locales\Serbian_Latin::init();
    7878
     79                // Correct `WP_Locale` for variant locales in project lists.
     80                add_filter( 'gp_translation_sets_sort', [ $this, 'filter_gp_translation_sets_sort' ] );
     81
    7982                if ( defined( 'WP_CLI' ) && WP_CLI ) {
    8083                        $this->register_cli_commands();
    … …  
    571574                return $content;
    572575        }
     576
     577        /**
     578         * Filter the project translation set list to have correct WP_Locale fields for variants.
     579         *
     580         * This also affects the API output, so as not to have duplicate `wp_locale` fields with variants.
     581         *
     582         * @see https://meta.trac.wordpress.org/ticket/4367
     583         *
     584         * @param array $translation_sets The translation sets.
     585         * @return array Filtered translation sets.
     586         */
     587        function filter_gp_translation_sets_sort( $translation_sets ) {
     588                foreach ( $translation_sets as $set ) {
     589                        if ( 'default' !== $set->slug && ! str_contains( $set->wp_locale, $set->slug ) ) {
     590                                $set->wp_locale .= '_' . $set->slug;
     591                        }
     592                }
     593
     594                return $translation_sets;
     595        }
    573596}
Note: See TracChangeset for help on using the changeset viewer.