Making WordPress.org

Ticket #7675: 2428.patch

File 2428.patch, 3.4 KB (added by renyot, 4 weeks ago)
  • lang-guess-ajax.php

     
    3535        $is_home        = ( '/' == $uri );
    3636        $is_forums      = ( '/support/' == $uri || '/support/forums/' == $uri || '/documentation/' == $uri || '/documentation-test/' == $uri );
    3737        $is_download    = ( '/download/' == $uri );
     38
    3839
    3940        if ( $is_download ) {
    4041                $locales_where = $wpdb->prepare( 'latest_release = %s', WP_CORE_LATEST_RELEASE );
     
    6263
    6364        if ( $is_forums ) {
    6465                $guesses = $guesser->guess_locales_subdomains_with_forums();
     66
     67
    6568        } else {
    6669                $guesses = $guesser->guess_locales_subdomains();
    6770        }
     
    7679                $anonymized_ip   = preg_replace( '!\.\d+$!', '.xxx', $_SERVER['REMOTE_ADDR'] );
    7780                $ip_country      = $guesser->get_country_by_ip();
    7881
    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 );
    8083                die();
    8184        }
    8285
    8386        // Check the referring site, and filter out that locale.
    8487        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                       
    8892                        $guesses = array_filter(
    8993                                $guesses,
    90                                 function( $guess ) use ( $ref_site ) {
    91                                         return $guess['subdomain'] !== $ref_site;
     94                                function( $guess ) use ( $ref_e ) {
     95                                        return $guess['e;
    9296                                }
    9397                        );
    9498                        $guesses = array_values( $guesses );
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
    95112                }
    96113        }
    97114
     
    98115        if ( is_array( $guesses ) && ! empty( $guesses ) ) {
    99116                if ( $is_forums ) {
    100117                        $string = translate_gp( 'WordPress support forums are also available in %s.', $guesses[0]['locale'] );
     118
     119
    101120                } else {
    102121                        $string = translate_gp( 'WordPress is also available in %s.', $guesses[0]['locale'] );
    103122                }
     
    104123
    105124                $translated = array();
    106125                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'] ) ) {
    108130                                $path = '/';
    109131                                if ( $is_forums ) {
    110132                                        $path = '/support/';