Making WordPress.org


Ignore:
Timestamp:
03/18/2021 05:13:45 AM (6 years ago)
Author:
dd32
Message:

Locale Detection: Some language codes do not follow the xx_XX format, and xx_xxxxx is valid, likewise some locales have variants, allow for those too.

This affected locales such as art_xpirate which would revert to art_emoji or ca_valencia which reverted to ca.

This also affected de_CH_informal which would revert to de_DE, or de_CH_404 which reverted to de_DE instead of de_CH.

See #5662.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/locale-detection/class-detector.php

    r10106 r10829  
    174174        public function check_variants( $locale ) {
    175175                $locale   = str_replace( '-', '_', $locale );
    176                 $locale   = explode( '_', $locale, 2 );
     176                $locale   = explode( '_', $locale, 3 );
    177177                $variants = [];
    178178
    179179                if ( 1 === count( $locale ) ) {
    180180                        $lang = strtolower( $locale[0] );
     181                } elseif ( 2 === count( $locale ) ) {
     182                        list( $lang, $region ) = $locale;
     183
     184                        $lang       = strtolower( $lang );
     185                        $variants[] = $lang . '_' . strtolower( $region );
     186                        $variants[] = $lang . '_' . strtoupper( $region );
    181187                } else {
    182                         list( $lang, $region ) = $locale;
     188                        list( $lang, $region, $variant ) = $locale;
    183189
    184190                        $lang       = strtolower( $lang );
     191                        $variant    = strtolower( $variant );
     192                        $variants[] = $lang . '_' . strtolower( $region ) . '_' . $variant;
     193                        $variants[] = $lang . '_' . strtoupper( $region ) . '_' . $variant;
     194                        $variants[] = $lang . '_' . strtolower( $region );
    185195                        $variants[] = $lang . '_' . strtoupper( $region );
    186196                }
Note: See TracChangeset for help on using the changeset viewer.