mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Filter PayPal-supported language codes
This commit is contained in:
parent
e13dfad27c
commit
845a83acb4
4 changed files with 105 additions and 2 deletions
|
@ -46,7 +46,7 @@ class ApplicationContextRepository {
|
|||
): ApplicationContext {
|
||||
|
||||
$brand_name = $this->settings->has( 'brand_name' ) ? $this->settings->get( 'brand_name' ) : '';
|
||||
$locale = str_replace( '_', '-', get_user_locale() );
|
||||
$locale = $this->valid_bcp47_code();
|
||||
$landingpage = $this->settings->has( 'landing_page' ) ?
|
||||
$this->settings->get( 'landing_page' ) : ApplicationContext::LANDING_PAGE_NO_PREFERENCE;
|
||||
$context = new ApplicationContext(
|
||||
|
@ -59,4 +59,20 @@ class ApplicationContextRepository {
|
|||
);
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PayPal-supported BCP-47 code, for example de-DE-formal becomes de-DE.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function valid_bcp47_code() {
|
||||
$locale = str_replace( '_', '-', get_user_locale() );
|
||||
$parts = explode( '-', $locale );
|
||||
|
||||
if ( count( $parts ) < 3 ) {
|
||||
return $locale;
|
||||
}
|
||||
|
||||
return substr( $locale, 0, strrpos( $locale, '-' ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -726,7 +726,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
$params = array(
|
||||
'client-id' => $this->client_id,
|
||||
'currency' => get_woocommerce_currency(),
|
||||
'locale' => get_user_locale(),
|
||||
'locale' => $this->valid_locale_code(),
|
||||
'integration-date' => PAYPAL_INTEGRATION_DATE,
|
||||
'components' => implode( ',', $this->components() ),
|
||||
'vault' => $this->can_save_vault_token() ?
|
||||
|
@ -957,4 +957,20 @@ class SmartButton implements SmartButtonInterface {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PayPal-supported locale code, for example de_DE_formal becomes de_DE.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function valid_locale_code(): string {
|
||||
$locale = get_user_locale();
|
||||
$parts = explode( '_', $locale );
|
||||
|
||||
if ( count( $parts ) < 3 ) {
|
||||
return $locale;
|
||||
}
|
||||
|
||||
return substr( $locale, 0, strrpos( $locale, '_' ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue