WCML_Locale

The WooCommerce Multilingual WCML Locale class.

Defined (1)

The class is defined in the following location(s).

/inc/class-wcml-locale.php  
  1. class WCML_Locale{ 
  2.  
  3. private $woocommerce_wpml; 
  4. private $sitepress; 
  5.  
  6. public function __construct( &$woocommerce_wpml, &$sitepress ) { 
  7. $this->woocommerce_wpml = $woocommerce_wpml; 
  8. $this->sitepress = $sitepress; 
  9.  
  10. $this->load_locale(); 
  11.  
  12. add_filter( 'locale', array( $this, 'update_product_action_locale_check' ) ); 
  13. add_action( 'woocommerce_email', array( $this, 'woocommerce_email_refresh_text_domain' ) ); 
  14. add_action( 'wp_ajax_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 ); 
  15. add_action( 'wp_ajax_nopriv_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 ); 
  16.  
  17.  
  18. function load_locale() { 
  19. return load_plugin_textdomain( 'woocommerce-multilingual', false, WCML_PLUGIN_FOLDER.'/locale' ); 
  20.  
  21. public function switch_locale( $lang_code = false ) { 
  22. global $l10n; 
  23. static $original_l10n; 
  24. if ( ! empty( $lang_code ) ) { 
  25. $original_l10n = isset( $l10n[ 'woocommerce-multilingual' ] ) ? $l10n[ 'woocommerce-multilingual' ] : null; 
  26. if ( $original_l10n !== null ) { 
  27. unset( $l10n[ 'woocommerce-multilingual' ] ); 
  28. return load_textdomain( 'woocommerce-multilingual',  
  29. WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $this->sitepress->get_locale( $lang_code ) . '.mo' ); 
  30.  
  31. } else { // switch back 
  32. $l10n[ 'woocommerce-multilingual' ] = $original_l10n; 
  33.  
  34. /** Change locale to saving language - needs for sanitize_title exception wcml-390 */ 
  35. public function update_product_action_locale_check( $locale ) { 
  36. if( isset($_POST['action']) && $_POST['action'] == 'wpml_translation_dialog_save_job' ) { 
  37. return $this->sitepress->get_locale( $_POST[ 'job_details' ][ 'target' ] ); 
  38. return $locale; 
  39.  
  40. public function woocommerce_email_refresh_text_domain() { 
  41. if( !isset( $_GET[ 'page' ] ) || ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != 'wc-settings' ) ) { 
  42. $this->wcml_refresh_text_domain(); 
  43.  
  44. public function wcml_refresh_text_domain() { 
  45. global $woocommerce; 
  46. $domain = 'woocommerce'; 
  47. unload_textdomain( $domain ); 
  48. $woocommerce->load_plugin_textdomain(); 
  49.