From c3e5d21e75f6790ade6f9abc5003bc7a2fbd386d Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 12 Sep 2023 18:09:58 +0100 Subject: [PATCH] Add GooglePay button language/locale --- modules/ppcp-googlepay/extensions.php | 17 ++++++++ .../resources/js/GooglepayButton.js | 1 + modules/ppcp-googlepay/src/Assets/Button.php | 5 ++- .../src/Helper/PropertiesDictionary.php | 42 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-googlepay/extensions.php b/modules/ppcp-googlepay/extensions.php index 2ab5f2a94..7523c00bd 100644 --- a/modules/ppcp-googlepay/extensions.php +++ b/modules/ppcp-googlepay/extensions.php @@ -55,6 +55,7 @@ return array( 'elements' => array( '#field-googlepay_button_color', '#field-googlepay_button_type', + '#field-googlepay_button_language', '#field-googlepay_button_shipping_enabled', ), ), @@ -96,6 +97,22 @@ return array( 'gateway' => 'paypal', 'requirements' => array(), ), + 'googlepay_button_language' => array( + 'title' => str_repeat( ' ', 6 ) . __( 'Button Language', 'woocommerce-paypal-payments' ), + 'type' => 'select', + 'desc_tip' => true, + 'description' => __( + 'The language and region used for the displayed Google Pay button. The default value is the current language and region setting in a browser.', + 'woocommerce-paypal-payments' + ), + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => 'en', + 'options' => PropertiesDictionary::button_languages(), + 'screens' => array( State::STATE_ONBOARDED ), + 'gateway' => 'paypal', + 'requirements' => array(), + ), 'googlepay_button_shipping_enabled' => array( 'title' => str_repeat( ' ', 6 ) . __( 'Shipping Callback', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js index 69c02b1e9..6cd97302f 100644 --- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js +++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js @@ -149,6 +149,7 @@ class GooglepayButton { allowedPaymentMethods: [baseCardPaymentMethod], buttonColor: buttonStyle.color || 'black', buttonType: buttonStyle.type || 'pay', + buttonLocale: buttonStyle.language || 'en', buttonSizeMode: 'fill', }); jQuery(wrapper).append(button); diff --git a/modules/ppcp-googlepay/src/Assets/Button.php b/modules/ppcp-googlepay/src/Assets/Button.php index 86b499668..48848af56 100644 --- a/modules/ppcp-googlepay/src/Assets/Button.php +++ b/modules/ppcp-googlepay/src/Assets/Button.php @@ -388,8 +388,9 @@ class Button implements ButtonInterface { $context = str_replace( '-block', '', $context ); $values = array( - 'color' => 'black', - 'type' => 'pay', + 'color' => 'black', + 'type' => 'pay', + 'language' => 'en', ); foreach ( $values as $style => $value ) { diff --git a/modules/ppcp-googlepay/src/Helper/PropertiesDictionary.php b/modules/ppcp-googlepay/src/Helper/PropertiesDictionary.php index 9e0e31c60..d76219895 100644 --- a/modules/ppcp-googlepay/src/Helper/PropertiesDictionary.php +++ b/modules/ppcp-googlepay/src/Helper/PropertiesDictionary.php @@ -43,4 +43,46 @@ class PropertiesDictionary { 'subscribe' => __( 'Subscribe', 'woocommerce-paypal-payments' ), ); } + + /** + * Returns the possible list of button languages. + * + * @return array + */ + public static function button_languages(): array { + return array( + '' => __( 'Browser language', 'woocommerce-paypal-payments' ), + 'ar' => __( 'Arabic', 'woocommerce-paypal-payments' ), + 'bg' => __( 'Bulgarian', 'woocommerce-paypal-payments' ), + 'ca' => __( 'Catalan', 'woocommerce-paypal-payments' ), + 'zh' => __( 'Chinese', 'woocommerce-paypal-payments' ), + 'hr' => __( 'Croatian', 'woocommerce-paypal-payments' ), + 'cs' => __( 'Czech', 'woocommerce-paypal-payments' ), + 'da' => __( 'Danish', 'woocommerce-paypal-payments' ), + 'nl' => __( 'Dutch', 'woocommerce-paypal-payments' ), + 'en' => __( 'English', 'woocommerce-paypal-payments' ), + 'et' => __( 'Estonian', 'woocommerce-paypal-payments' ), + 'fi' => __( 'Finnish', 'woocommerce-paypal-payments' ), + 'fr' => __( 'French', 'woocommerce-paypal-payments' ), + 'de' => __( 'German', 'woocommerce-paypal-payments' ), + 'el' => __( 'Greek', 'woocommerce-paypal-payments' ), + 'id' => __( 'Indonesian', 'woocommerce-paypal-payments' ), + 'it' => __( 'Italian', 'woocommerce-paypal-payments' ), + 'ja' => __( 'Japanese', 'woocommerce-paypal-payments' ), + 'ko' => __( 'Korean', 'woocommerce-paypal-payments' ), + 'ms' => __( 'Malay', 'woocommerce-paypal-payments' ), + 'no' => __( 'Norwegian', 'woocommerce-paypal-payments' ), + 'pl' => __( 'Polish', 'woocommerce-paypal-payments' ), + 'pt' => __( 'Portuguese', 'woocommerce-paypal-payments' ), + 'ru' => __( 'Russian', 'woocommerce-paypal-payments' ), + 'sr' => __( 'Serbian', 'woocommerce-paypal-payments' ), + 'sk' => __( 'Slovak', 'woocommerce-paypal-payments' ), + 'sl' => __( 'Slovenian', 'woocommerce-paypal-payments' ), + 'es' => __( 'Spanish', 'woocommerce-paypal-payments' ), + 'sv' => __( 'Swedish', 'woocommerce-paypal-payments' ), + 'th' => __( 'Thai', 'woocommerce-paypal-payments' ), + 'tr' => __( 'Turkish', 'woocommerce-paypal-payments' ), + 'uk' => __( 'Ukrainian', 'woocommerce-paypal-payments' ), + ); + } }