Making WordPress.org

Changeset 6029


Ignore:
Timestamp:
10/14/2017 11:46:34 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Pull native language names for the locale banner from GP_Locales instead of the languages table.

Props joostdevalk.
Fixes #2618.

File:
1 edited

Legend:

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

    r5983 r6029  
    7373        $current_locale_is_translated = in_array( $current_locale, $translated_locales );
    7474
     75        require_once GLOTPRESS_LOCALES_PATH;
     76
    7577        // Get the native language names of the locales.
    7678        $suggest_named_locales = [];
    7779        foreach ( $suggest_locales as $locale ) {
    78             $name = $this->get_native_language_name( $locale );
    79             if ( $name ) {
    80                 $suggest_named_locales[ $locale ] = $name;
    81             }
     80            $suggest_named_locales[ $locale ] = \GP_Locales::by_field( 'wp_locale', $locale )->native_name;
    8281        }
    8382
     
    175174            $suggest_string = sprintf(
    176175                $this->translate( 'This plugin is not available in %1$s yet. <a href="%2$s">Help translate it!</a>', $current_locale ),
    177                 $this->get_native_language_name( $current_locale ),
     176                \GP_Locales::by_field( 'wp_locale', $current_locale )->native_name,
    178177                esc_url( 'https://translate.wordpress.org/projects/wp-plugins/' . $plugin_slug )
    179178            );
     
    313312        }
    314313
    315         require_once GLOTPRESS_LOCALES_PATH;
    316314        $gp_locale = \GP_Locales::by_field( 'wp_locale', $wp_locale )->slug;
    317315
     
    342340        return isset( $translations[ $gp_locale ] ) ? $translations[ $gp_locale ] : $string;
    343341    }
    344 
    345     protected function get_native_language_name( $locale ) {
    346         global $wpdb;
    347 
    348         $slug = str_replace( '_', '-', $locale );
    349         $slug = strtolower( $slug );
    350 
    351         $name = $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM languages WHERE slug = %s', $slug ) );
    352         if ( ! $name ) {
    353             $fallback_slug = explode( '-', $slug )[0]; // de-de => de
    354             $name = $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM languages WHERE slug = %s', $fallback_slug ) );
    355             if ( $name ) {
    356                 return $name;
    357             }
    358         } else {
    359             return $name;
    360         }
    361 
    362         return '';
    363     }
    364342}
    365343
Note: See TracChangeset for help on using the changeset viewer.