WCML_Attribute_Translation_UI

The WooCommerce Multilingual WCML Attribute Translation UI class.

Defined (1)

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

/inc/template-classes/class-wcml-attribute-translation-ui.php  
  1. class WCML_Attribute_Translation_UI extends WPML_Templates_Factory { 
  2.  
  3. private $woocommerce_wpml; 
  4. private $sitepress; 
  5.  
  6. public function __construct( &$woocommerce_wpml, &$sitepress ) { 
  7. parent::__construct(); 
  8.  
  9. $this->woocommerce_wpml = $woocommerce_wpml; 
  10. $this->sitepress = $sitepress; 
  11.  
  12. public function get_model() { 
  13.  
  14. $product_attributes = $this->woocommerce_wpml->attributes->get_translatable_attributes(); 
  15. $taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : false; 
  16. $selected_attribute = false; 
  17. $translation_ui = ''; 
  18.  
  19. if( $product_attributes && !empty( $taxonomy ) ) { 
  20. foreach ($product_attributes as $attribute) { 
  21. if ($attribute->attribute_name == $taxonomy) { 
  22. $selected_attribute = $attribute; 
  23. break; 
  24.  
  25. if( $selected_attribute ) { 
  26. $selected_attribute_name = $selected_attribute ? 'pa_' . $selected_attribute->attribute_name : ''; 
  27. $WPML_Translate_Taxonomy = 
  28. new WPML_Taxonomy_Translation( 
  29. $selected_attribute_name,  
  30. array( 
  31. 'taxonomy_selector'=> false 
  32. ); 
  33.  
  34. }elseif( $product_attributes ) { 
  35. $empty_value = new stdClass(); 
  36. $empty_value->attribute_name = ''; 
  37. $empty_value->attribute_label = __( '--Attribute--', 'woocommerce-multilingual' ); 
  38. array_unshift( $product_attributes, $empty_value ); 
  39.  
  40. $WPML_Translate_Taxonomy = 
  41. new WPML_Taxonomy_Translation( 
  42. '',  
  43. array( 
  44. 'taxonomy_selector' => false 
  45. ),  
  46. new WPML_UI_Screen_Options_Factory( $this->sitepress ) 
  47. ); 
  48.  
  49. if( isset( $WPML_Translate_Taxonomy ) ) { 
  50. ob_start(); 
  51. $WPML_Translate_Taxonomy->render(); 
  52. $translation_ui = ob_get_contents(); 
  53. ob_end_clean(); 
  54.  
  55. $model = array( 
  56. 'attributes' => $product_attributes,  
  57. 'selected_attribute' => $selected_attribute,  
  58. 'strings' => array( 
  59. 'no_attributes' => __( 'There are no translatable product attributes defined', 'woocommerce-multilingual' ),  
  60. 'select_label' => __('Select the attribute to translate: ', 'woocommerce-multilingual'),  
  61. 'loading' => __( 'Loading ...', 'woocommerce-multilingual' ) 
  62. ),  
  63. 'translation_ui' => $translation_ui 
  64.  
  65. ); 
  66.  
  67. return $model; 
  68.  
  69. public function init_template_base_dir() { 
  70. $this->template_paths = array( 
  71. WCML_PLUGIN_PATH . '/templates/',  
  72. ); 
  73.  
  74. public function get_template() { 
  75. return 'attribute-translation.twig';