Ejegg has uploaded a new change for review.

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

Change subject: NumberFormatter fallback when ext-intl not installed
......................................................................

NumberFormatter fallback when ext-intl not installed

The only other class we're using from the Intl extension is
Transliterator, and we've got a class_exists check around that.
Do the same for NumberFormatter in the hopes of making DI useful
in more situations.

Change-Id: I0a0c40ad95a33198e6d7967777a83e5b3da2130b
---
M gateway_forms/Mustache.php
M tests/Adapter/Amazon/AmazonTest.php
2 files changed, 17 insertions(+), 8 deletions(-)


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

diff --git a/gateway_forms/Mustache.php b/gateway_forms/Mustache.php
index abb80e9..182d10b 100644
--- a/gateway_forms/Mustache.php
+++ b/gateway_forms/Mustache.php
@@ -207,11 +207,16 @@
                                'selected' => ( $currency === 
$data['currency_code'] ),
                        );
                }
-               $locale = $data['language'] . '_' . $data['country'];
-               $formatter = new NumberFormatter( $locale, 
NumberFormatter::CURRENCY );
-               $data['display_amount'] = $formatter->formatCurrency(
-                       $data['amount'], $data['currency_code']
-               );
+               if ( class_exists( 'NumberFormatter' ) ) {
+                       $locale = $data['language'] . '_' . $data['country'];
+                       $formatter = new NumberFormatter( $locale, 
NumberFormatter::CURRENCY );
+                       $data['display_amount'] = $formatter->formatCurrency(
+                               $data['amount'],
+                               $data['currency_code']
+                       );
+               } else {
+                       $data['display_amount'] = "{$data['amount']} 
{$data['currency_code']}";
+               }
        }
 
        /**
diff --git a/tests/Adapter/Amazon/AmazonTest.php 
b/tests/Adapter/Amazon/AmazonTest.php
index bf4dbc5..1bcd5c7 100644
--- a/tests/Adapter/Amazon/AmazonTest.php
+++ b/tests/Adapter/Amazon/AmazonTest.php
@@ -87,9 +87,13 @@
                        'donate_interface-fallback-currency-notice',
                        'USD'
                )->inLanguage( $language )->text();
-               $locale = $init['language'] . '_' . $init['country'];
-               $formatter = new NumberFormatter( $locale, 
NumberFormatter::CURRENCY );
-               $expectedDisplayAmount = $formatter->formatCurrency( 
$expectedAmount, 'USD' );
+               if ( class_exists( 'NumberFormatter' ) ) {
+                       $locale = $init['language'] . '_' . $init['country'];
+                       $formatter = new NumberFormatter( $locale, 
NumberFormatter::CURRENCY );
+                       $expectedDisplayAmount = $formatter->formatCurrency( 
$expectedAmount, 'USD' );
+               } else {
+                       $expectedDisplayAmount = "$expectedAmount USD";
+               }
 
                $that = $this; //needed for PHP pre-5.4
                $convertTest = function( $amountString ) use ( 
$expectedDisplayAmount, $that ) {

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

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

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

Reply via email to