WordPress.org

Making WordPress.org

Changeset 3540


Ignore:
Timestamp:
06/22/2016 10:58:39 AM (2 years ago)
Author:
ocean90
Message:

Plugin Directory: Fix locale banner for browsers which are sending an en-us language header.

See #1728.

File:
1 edited

Legend:

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

    r3534 r3540  
    152152        if ( is_array( $http_locales ) ) {
    153153            foreach ( $http_locales as $http_locale ) {
     154                @list( $lang, $region ) = explode( '-', $http_locale );
     155                if ( is_null( $region ) ) {
     156                    $region = $lang;
     157                }
     158
    154159                /*
    155160                 * Discard English -- it's the default for all browsers,
    156161                 * ergo not very reliable information
    157162                 */
    158                 if ( 'en' === $http_locale || 'en-US' === $http_locale ) {
     163                if ( 'en' === $lang ) {
    159164                    continue;
    160165                }
    161166
    162                 @list( $lang, $region ) = explode( '-', $http_locale );
    163                 if ( is_null( $region ) ) {
    164                     $region = $lang;
    165                 }
     167                // Region should be uppercase.
     168                $region = strtoupper( $region );
    166169
    167170                if ( $mapped = $this->map_locale( $lang, $region, $available_locales ) ) {
     
    273276        unset( $translation );
    274277
    275     #   wp_cache_add( 'original-' . $original_id, $translations, 'lang-guess-translations', 900 );
     278        wp_cache_add( 'original-' . $original_id, $translations, 'lang-guess-translations', 900 );
    276279
    277280        return isset( $translations[ $gp_locale ] ) ? $translations[ $gp_locale ] : $string;
Note: See TracChangeset for help on using the changeset viewer.