Ticket #2690: 2690.patch
File 2690.patch, 5.9 KB (added by , 8 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php
464 464 } 465 465 } 466 466 467 $locale_sites = $this->get_locale_sites(); 468 469 foreach ( $locales as $key => $locale ) { 470 if ( isset( $locale_sites[ $locale->wp_locale ] ) ) { 471 $locale->subdomain = $locale_sites[ $locale->wp_locale ]->subdomain; 472 } else { 473 unset( $locales[ $key ] ); 474 } 475 } 476 467 477 return $locales; 468 478 } 479 480 /** 481 * Returns a list of locale sites. 482 * 483 * @return array 484 */ 485 public function get_locale_sites() { 486 wp_cache_add_global_groups( array( 'locale-associations' ) ); 487 488 if ( false === ( $sites = wp_cache_get( 'local-sites', 'locale-associations' ) ) ) { 489 global $wpdb; 490 491 $sites = $wpdb->get_results( 'SELECT locale, subdomain FROM locales', OBJECT_K ); 492 if ( ! $sites ) { 493 return; 494 } 495 496 require_once GLOTPRESS_LOCALES_PATH; 497 498 foreach ( $sites as $site ) { 499 $gp_locale = \GP_Locales::by_field( 'wp_locale', $site->locale ); 500 if ( ! $gp_locale ) { 501 unset( $sites[ $site->locale ] ); 502 continue; 503 } 504 505 $hreflang = false; 506 507 // Note that Google only supports ISO 639-1 codes. 508 if ( isset( $gp_locale->lang_code_iso_639_1 ) && isset( $gp_locale->country_code ) ) { 509 $hreflang = $gp_locale->lang_code_iso_639_1 . '-' . $gp_locale->country_code; 510 } elseif ( isset( $gp_locale->lang_code_iso_639_1 ) ) { 511 $hreflang = $gp_locale->lang_code_iso_639_1; 512 } elseif ( isset( $gp_locale->lang_code_iso_639_2 ) ) { 513 $hreflang = $gp_locale->lang_code_iso_639_2; 514 } elseif ( isset( $gp_locale->lang_code_iso_639_3 ) ) { 515 $hreflang = $gp_locale->lang_code_iso_639_3; 516 } 517 518 if ( $hreflang && 'art' !== $hreflang ) { 519 $sites[ $site->locale ]->hreflang = strtolower( $hreflang ); 520 } else { 521 unset( $sites[ $site->locale ] ); 522 } 523 } 524 525 // Add en_US to the list of sites. 526 $sites['en_US'] = (object) array( 527 'locale' => 'en_US', 528 'hreflang' => 'en', 529 'subdomain' => '' 530 ); 531 532 uasort( $sites, function( $a, $b ) { 533 return strcasecmp( $a->hreflang, $b->hreflang ); 534 } ); 535 536 wp_cache_set( 'local-sites', $sites, 'locale-associations' ); 537 } 538 539 return $sites; 540 } 469 541 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-developers.php
34 34 35 35 if ( ! empty( $locales ) ) { 36 36 $locales_list = implode( ', ', array_map( function( $locale ) use ( $slug ) { 37 return sprintf( '<a href="%1$s">%2$s</a>', esc_url( " {$locale->locale}.wordpress.org/plugins/{$slug}/" ), $locale->name );37 return sprintf( '<a href="%1$s">%2$s</a>', esc_url( "https://{$locale->subdomain}.wordpress.org/plugins/{$slug}/" ), $locale->name ); 38 38 }, $locales ) ); 39 39 /* Translators: 1: Plugin name; 2: Number of locales; 3: List of locales; */ 40 40 $output .= sprintf( '%1$s has been translated into these %2$d locales: %3$s.', $title, count( $locales ), $locales_list ) . ' '; -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php
245 245 * @link https://sites.google.com/site/webmasterhelpforum/en/faq-internationalisation FAQ: Internationalisation. 246 246 */ 247 247 function hreflang_link_attributes() { 248 wp_cache_add_global_groups( array( 'locale-associations' ) ); 249 250 if ( false === ( $sites = wp_cache_get( 'local-sites', 'locale-associations' ) ) ) { 251 global $wpdb; 252 253 $sites = $wpdb->get_results( 'SELECT locale, subdomain FROM locales', OBJECT_K ); 254 if ( ! $sites ) { 255 return; 256 } 257 258 require_once GLOTPRESS_LOCALES_PATH; 259 260 foreach ( $sites as $site ) { 261 $gp_locale = \GP_Locales::by_field( 'wp_locale', $site->locale ); 262 if ( ! $gp_locale ) { 263 unset( $sites[ $site->locale ] ); 264 continue; 265 } 266 267 $hreflang = false; 268 269 // Note that Google only supports ISO 639-1 codes. 270 if ( isset( $gp_locale->lang_code_iso_639_1 ) && isset( $gp_locale->country_code ) ) { 271 $hreflang = $gp_locale->lang_code_iso_639_1 . '-' . $gp_locale->country_code; 272 } elseif ( isset( $gp_locale->lang_code_iso_639_1 ) ) { 273 $hreflang = $gp_locale->lang_code_iso_639_1; 274 } elseif ( isset( $gp_locale->lang_code_iso_639_2 ) ) { 275 $hreflang = $gp_locale->lang_code_iso_639_2; 276 } elseif ( isset( $gp_locale->lang_code_iso_639_3 ) ) { 277 $hreflang = $gp_locale->lang_code_iso_639_3; 278 } 279 280 if ( $hreflang && 'art' !== $hreflang ) { 281 $sites[ $site->locale ]->hreflang = strtolower( $hreflang ); 282 } else { 283 unset( $sites[ $site->locale ] ); 284 } 285 } 286 287 // Add en_US to the list of sites. 288 $sites['en_US'] = (object) array( 289 'locale' => 'en_US', 290 'hreflang' => 'en', 291 'subdomain' => '' 292 ); 293 294 uasort( $sites, function( $a, $b ) { 295 return strcasecmp( $a->hreflang, $b->hreflang ); 296 } ); 297 298 wp_cache_set( 'local-sites', $sites, 'locale-associations' ); 248 if ( class_exists( '\WordPressdotorg\Plugin_Directory\Plugin_I18n' ) ) { 249 $sites = \WordPressdotorg\Plugin_Directory\Plugin_I18n::instance()->get_locale_sites(); 250 } else { 251 $sites = array(); 299 252 } 300 253 301 254 foreach ( $sites as $site ) {