Ticket #2618: 2618.2.patch
File 2618.2.patch, 5.4 KB (added by , 7 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-locale-banner.php
33 33 34 34 $plugin_slug = $request['plugin_slug']; 35 35 36 // Get the locale subdomain associations used to link languages to their local site. 37 $locale_subdomain_assoc = $wpdb->get_results( 38 "SELECT locale, subdomain FROM locales WHERE locale NOT LIKE '%\_%\_%'", OBJECT_K // Don't grab variants, for now. 39 ); 36 // Get the locale sites used to link languages to their local site. 37 $locale_sites = get_sites( [ 38 'network_id' => WPORG_GLOBAL_NETWORK_ID, 39 'public' => 1, 40 'path' => '/', 41 'number' => '', 42 ] ); 40 43 41 44 // Retrieve all the WordPress locales. 42 $all_locales = wp_list_pluck( $locale_s ubdomain_assoc, 'locale' );45 $all_locales = wp_list_pluck( $locale_sites, 'locale' ); 43 46 47 $locale_site_assoc = array_combine( $all_locales, $locale_sites ); 48 44 49 $is_plugin_request = ! empty( $plugin_slug ); 45 50 46 51 if ( $is_plugin_request ) { … … 75 80 // Get the native language names of the locales. 76 81 $suggest_named_locales = []; 77 82 foreach ( $suggest_locales as $locale ) { 78 $name = $this->get_native_language_name( $locale ); 79 if ( $name ) { 80 $suggest_named_locales[ $locale ] = $name; 81 } 83 $suggest_named_locales[ $locale ] = $locale_site_assoc[ $locale ]->blogname; 82 84 } 83 85 84 86 $suggest_string = ''; … … 96 98 $suggest_string = sprintf( 97 99 $this->translate( 'This plugin is also available in %s.', $locale ), 98 100 sprintf( 99 '<a href="https://%s .wordpress.org%s%s/">%s</a>',100 $locale_s ubdomain_assoc[ $locale ]->subdomain,101 '<a href="https://%s%s%s/">%s</a>', 102 $locale_site_assoc[ $locale ]->domain, 101 103 $current_site->path, 102 104 $plugin_slug, 103 105 $language … … 107 109 $suggest_string = sprintf( 108 110 $this->translate( 'The plugin directory is also available in %s.', $locale ), 109 111 sprintf( 110 '<a href="https://%s .wordpress.org%s">%s</a>',111 $locale_s ubdomain_assoc[ $locale ]->subdomain,112 '<a href="https://%s%s">%s</a>', 113 $locale_site_assoc[ $locale ]->domain, 112 114 $current_site->path, 113 115 $language 114 116 ) … … 125 127 $other_suggest = ''; 126 128 foreach ( $suggest_named_locales as $locale => $language ) { 127 129 $other_suggest .= sprintf( 128 '<a href="https://%s .wordpress.org%s%s/">%s</a>, ',129 $locale_s ubdomain_assoc[ $locale ]->subdomain,130 '<a href="https://%s%s%s/">%s</a>, ', 131 $locale_site_assoc[ $locale ]->domain, 130 132 $current_site->path, 131 133 $plugin_slug, 132 134 $language … … 136 138 $suggest_string = sprintf( 137 139 $this->translate( 'This plugin is also available in %1$s (also: %2$s).', $primary_locale ), 138 140 sprintf( 139 '<a href="https://%s .wordpress.org%s%s/">%s</a>',140 $locale_s ubdomain_assoc[ $primary_locale ]->subdomain,141 '<a href="https://%s%s%s/">%s</a>', 142 $locale_site_assoc[ $primary_locale ]->domain, 141 143 $current_site->path, 142 144 $plugin_slug, 143 145 $primary_language … … 148 150 $other_suggest = ''; 149 151 foreach ( $suggest_named_locales as $locale => $language ) { 150 152 $other_suggest .= sprintf( 151 '<a href="https://%s .wordpress.org%s">%s</a>, ',152 $locale_s ubdomain_assoc[ $locale ]->subdomain,153 '<a href="https://%s%s">%s</a>, ', 154 $locale_site_assoc[ $locale ]->domain, 153 155 $current_site->path, 154 156 $language 155 157 ); … … 158 160 $suggest_string = sprintf( 159 161 $this->translate( 'The plugin directory is also available in %1$s (also: %2$s).', $primary_locale ), 160 162 sprintf( 161 '<a href="https://%s .wordpress.org%s">%s</a>',162 $locale_s ubdomain_assoc[ $primary_locale ]->subdomain,163 '<a href="https://%s%s">%s</a>', 164 $locale_site_assoc[ $primary_locale ]->domain, 163 165 $current_site->path, 164 166 $primary_language 165 167 ), … … 172 174 } elseif ( ! $current_locale_is_suggested && ! $current_locale_is_translated && $is_plugin_request ) { 173 175 $suggest_string = sprintf( 174 176 $this->translate( 'This plugin is not available in %1$s yet. <a href="%2$s">Help translate it!</a>', $current_locale ), 175 $ this->get_native_language_name( $current_locale ),177 $locale_sites_assoc[ $locale ]->blogname, 176 178 esc_url( 'https://translate.wordpress.org/projects/wp-plugins/' . $plugin_slug ) 177 179 ); 178 180 } … … 339 341 340 342 return isset( $translations[ $gp_locale ] ) ? $translations[ $gp_locale ] : $string; 341 343 } 342 343 protected function get_native_language_name( $locale ) {344 global $wpdb;345 346 $slug = str_replace( '_', '-', $locale );347 $slug = strtolower( $slug );348 349 $name = $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM languages WHERE slug = %s', $slug ) );350 if ( ! $name ) {351 $fallback_slug = explode( '-', $slug )[0]; // de-de => de352 $name = $wpdb->get_var( $wpdb->prepare( 'SELECT name FROM languages WHERE slug = %s', $fallback_slug ) );353 if ( $name ) {354 return $name;355 }356 } else {357 return $name;358 }359 360 return '';361 }362 344 } 363 345 364 346 // Strings for the POT file.