Making WordPress.org

Changeset 1925


Ignore:
Timestamp:
09/30/2015 02:08:58 PM (11 years ago)
Author:
ocean90
Message:

GlotPress Translate Bridge: Use GP_Locales to get the GlotPress slug of a locale.

The previous version (now used as a fallback) assumed that the GlotPress locale for the WordPress locale he_IL is he-il, but it's he.

Fixes #1275.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/glotpress-translate-bridge/glotpress-translate-bridge.php

    r1793 r1925  
    138138                                LEFT JOIN {$this->gp_prefix}translations t ON t.original_id = o.id AND t.translation_set_id = s.id
    139139
    140                         WHERE 
     140                        WHERE
    141141                                $sql_project AND $sql_singular AND $sql_plural AND $sql_context AND $sql_locale
    142142                                AND o.status = '+active'
    … …  
    161161         * Determines the GlotPress Locale for a given WordPress Locale
    162162         *
    163          * This makes assumptions about the format of a GlotPress slug, which may not reflect real-world use-cases.
     163         * Uses `GP_Locales` if 'GLOTPRESS_LOCALES_PATH' is defined. Otherwise it makes assumptions about the format of a GlotPress slug,
     164         * which may not reflect real-world use-cases.
    164165         *
    165166         * @access private
    … …  
    168169         */
    169170        private function glotpress_locale() {
    170                 $gp_locale = strtolower( get_locale() );
    171 
    172                 if ( 'en_us' === $gp_locale ) {
     171                $wp_locale = get_locale();
     172
     173                if ( 'en_US' === $wp_locale ) {
    173174                        return false;
    174175                }
    175176
    176                 preg_match( '!^([a-z]{2,3})(_([a-z]{2}))?(_([a-z0-9]+))?$!', $gp_locale, $matches );
    177 
     177                preg_match( '!^([a-z]{2,3})(_([A-Z]{2}))?(_([a-z0-9]+))?$!', $wp_locale, $matches );
     178
     179                $wp_locale = $matches[1] . $matches[2];
    178180                $locale = $matches[1];
    179181                $country = isset( $matches[3] ) ? $matches[3] : $matches[1];
    180182                $variant = isset( $matches[5] ) ? $matches[5] : false;
    181        
    182                 if ( $locale !== $country ) {
    183                         $locale .= '-' . $country;
     183
     184                if ( defined( 'GLOTPRESS_LOCALES_PATH' ) ) {
     185                        require_once( GLOTPRESS_LOCALES_PATH );
     186
     187                        $gp_locale = GP_Locales::by_field( 'wp_locale', $wp_locale );
     188                        if ( $gp_locale ) {
     189                                $locale = $gp_locale->slug;
     190                        }
     191                } else {
     192                        $country = strtolower( $country );
     193                        if ( $locale !== $country ) {
     194                                $locale .= '-' . $country;
     195                        }
    184196                }
    185197
Note: See TracChangeset for help on using the changeset viewer.