Adamw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/63249


Change subject: WIP: more paypal language fixes
......................................................................

WIP: more paypal language fixes

We're waiting on PayPal support to explain why country= always overrides lc=

Change-Id: Ie99ebc1c88fdadb063147e728ec63018041644a1
---
M paypal_gateway/paypal.adapter.php
1 file changed, 53 insertions(+), 27 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/49/63249/1

diff --git a/paypal_gateway/paypal.adapter.php 
b/paypal_gateway/paypal.adapter.php
index e7681f7..ffcd7de 100644
--- a/paypal_gateway/paypal.adapter.php
+++ b/paypal_gateway/paypal.adapter.php
@@ -187,33 +187,37 @@
                }
        }
 
+       /**
+        * This is blood-curdling.  PayPal supports some languages only when 
given the
+        * country.  And, there seem to be lots of undocumented locales.
+        *
+        * We make the best of the situation by attempting full locales, then 
falling
+        * back to psuedo-national-language codes.
+        *
+        * There seems to be nothing we can do about countries for which PayPal
+        * assumes a national language, but the user is requesting another
+        * language.  The language will be switched as soon as they enter their
+        * country in the PP UI.
+        */
        protected function stage_locale( $mode = 'request' ) {
-               $supported_countries = array(
-                       'AU',
-                       'AT',
-                       'BE',
-                       'BR',
-                       'CA',
-                       'CH',
-                       'CN',
-                       'DE',
-                       'ES',
-                       'GB',
-                       'FR',
-                       'IT',
-                       'NL',
-                       'PL',
-                       'PT',
-                       'RU',
-                       'US',
-               );
                $supported_full_locales = array(
                        'da_DK',
+                       'de_AT',
+                       'de_CH',
+                       'en_AU',
+                       'en_CA',
+                       'en_GB',
+                       'en_US',
+                       'es_MX',
+                       'fr_CA',
+                       'fr_BE',
                        'he_IL',
                        'id_ID',
                        'jp_JP',
+                       'nl_BE',
                        'no_NO',
                        'pt_BR',
+                       'pt_PT',
                        'ru_RU',
                        'sv_SE',
                        'th_TH',
@@ -222,19 +226,41 @@
                        'zh_HK',
                        'zh_TW',
                );
+               $national_langs = array(
+                       'de' => 'DE',
+                       'en' => 'US',
+                       'es' => 'ES',
+                       'fr' => 'FR',
+                       'it' => 'IT',
+                       'nl' => 'NL',
+                       'pl' => 'PL',
+                       'pt' => 'PT',
+                       'ru' => 'RU',
+                       'zh' => 'CN',
+               );
 
-               $this->log("locale");
-               if ( in_array( $this->staged_data['country'], 
$supported_countries ) ) {
-                       $this->staged_data['locale'] = 
$this->staged_data['country'];
-               }
+               $lang = strtolower( $this->staged_data['language'] );
+               $country = strtoupper( $this->staged_data['country'] );
 
-               $fallbacks = Language::getFallbacksFor( strtolower( 
$this->staged_data['language'] ) );
+               $fallbacks = Language::getFallbacksFor( $lang );
+               array_unshift( $fallbacks, $lang );
+
                foreach ( $fallbacks as $lang ) {
-                       $locale = 
"{$this->staged_data['language']}_{$this->staged_data['country']}";
+                       $locale = "{$lang}_{$this->staged_data['country']}";
                        if ( in_array( $locale, $supported_full_locales ) ) {
-                               $this->staged_data['locale'] = $locale;
-                               return;
+                               break;
+                       }
+                       if ( array_key_exists( $lang, $national_langs ) ) {
+                               $locale = $national_langs[$lang];
+                               if ( $country !== $locale ) {
+                                       // FIXME: wheeeee
+                                       //$this->staged_data['country'] = 
$locale;
+                               }
+                               break;
                        }
                }
+               $this->staged_data['locale'] = $locale;
+
+               $this->log("locale for paypal: {$this->staged_data['locale']}");
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/63249
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie99ebc1c88fdadb063147e728ec63018041644a1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to