Ticket #7675: 2428.patch
File 2428.patch, 3.4 KB (added by , 4 weeks ago) |
---|
-
lang-guess-ajax.php
35 35 $is_home = ( '/' == $uri ); 36 36 $is_forums = ( '/support/' == $uri || '/support/forums/' == $uri || '/documentation/' == $uri || '/documentation-test/' == $uri ); 37 37 $is_download = ( '/download/' == $uri ); 38 38 39 39 40 if ( $is_download ) { 40 41 $locales_where = $wpdb->prepare( 'latest_release = %s', WP_CORE_LATEST_RELEASE ); … … 62 63 63 64 if ( $is_forums ) { 64 65 $guesses = $guesser->guess_locales_subdomains_with_forums(); 66 67 65 68 } else { 66 69 $guesses = $guesser->guess_locales_subdomains(); 67 70 } … … 76 79 $anonymized_ip = preg_replace( '!\.\d+$!', '.xxx', $_SERVER['REMOTE_ADDR'] ); 77 80 $ip_country = $guesser->get_country_by_ip(); 78 81 79 echo json_encode( compact( 'language_header', 'anonymized_ip', 'ip_country', 'guesses', 'is_home', 'is_forums', 'is_download' ), JSON_PRETTY_PRINT );82 echo json_encode( compact( 'language_header', 'anonymized_ip', 'ip_country', 'guesses', 'is_home', 'is_forums', 'is_download' ), JSON_PRETTY_PRINT ); 80 83 die(); 81 84 } 82 85 83 86 // Check the referring site, and filter out that locale. 84 87 if ( isset( $_SERVER['HTTP_REFERER'] ) ) { 85 $ref_site = parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ); 86 $ref_site = rtrim( str_replace( 'wordpress.org', '', $ref_site ), '.' ); 87 if ( $ref_site ) { 88 // The locale for Learn comes from the query parameter rather than the subdomain. 89 if ( $is_learn && isset( $_GET['locale'] ) ) { 90 $ref_locale = $_GET['locale']; 91 88 92 $guesses = array_filter( 89 93 $guesses, 90 function( $guess ) use ( $ref_ site ) {91 return $guess[' subdomain'] !== $ref_site;94 function( $guess ) use ( $ref_e ) { 95 return $guess['e; 92 96 } 93 97 ); 94 98 $guesses = array_values( $guesses ); 99 100 101 102 103 104 105 106 107 108 109 110 111 95 112 } 96 113 } 97 114 … … 98 115 if ( is_array( $guesses ) && ! empty( $guesses ) ) { 99 116 if ( $is_forums ) { 100 117 $string = translate_gp( 'WordPress support forums are also available in %s.', $guesses[0]['locale'] ); 118 119 101 120 } else { 102 121 $string = translate_gp( 'WordPress is also available in %s.', $guesses[0]['locale'] ); 103 122 } … … 104 123 105 124 $translated = array(); 106 125 foreach ( $guesses as $guess ) { 107 if ( isset( $guess['name'], $guess['subdomain'] ) ) { 126 if ( $is_learn ) { 127 $name = \GP_Locales::by_field( 'wp_locale', $guess['locale'] )->native_name; 128 $translated[] = "<a href='https://learn.wordpress.org/?locale={$guess['locale']}'>{$name}</a>"; 129 } elseif ( isset( $guess['name'], $guess['subdomain'] ) ) { 108 130 $path = '/'; 109 131 if ( $is_forums ) { 110 132 $path = '/support/';