Weglot Translate – Translate your WP website - Version 1.8

Version Description

  • Add new banner and icon
  • improve wc redirection
  • can now translate email
Download this release

Release Info

Developer remyb92
Plugin Icon 128x128 Weglot Translate – Translate your WP website
Version 1.8
Comparing to
See all releases

Code changes from version 1.7.1 to 1.8

Files changed (3) hide show
  1. WeglotPHPClient/src/Client.php +2 -1
  2. readme.txt +8 -2
  3. weglot.php +55 -8
WeglotPHPClient/src/Client.php CHANGED
@@ -39,6 +39,7 @@ class Client {
39
  public function checkText( $row ) {
40
  return ($row->parent()->tag != 'script'
41
  && $row->parent()->tag != 'style'
 
42
  && ! is_numeric( $this->full_trim( $row->outertext ) )
43
  && ! preg_match( '/^\d+%$/',$this->full_trim( $row->outertext ) )
44
  && strpos( $row->outertext,'[vc_' ) === false);
@@ -390,7 +391,7 @@ class Client {
390
 
391
  if ($nodes[$i]['type'] == 'img_src') {
392
  $nodes[$i]['node']->src = $translated_words[$i];
393
- if ($nodes[$i]['node']->hasAttribute('srcset') && $nodes[$i]['node']->srcset != '' && $translated_words[$i] != $words[$i]['w']) {
394
  $nodes[$i]['node']->srcset = '';
395
  }
396
  }
39
  public function checkText( $row ) {
40
  return ($row->parent()->tag != 'script'
41
  && $row->parent()->tag != 'style'
42
+ && $row->parent()->tag != 'noscript'
43
  && ! is_numeric( $this->full_trim( $row->outertext ) )
44
  && ! preg_match( '/^\d+%$/',$this->full_trim( $row->outertext ) )
45
  && strpos( $row->outertext,'[vc_' ) === false);
391
 
392
  if ($nodes[$i]['type'] == 'img_src') {
393
  $nodes[$i]['node']->src = $translated_words[$i];
394
+ if ($nodes[$i]['node']->hasAttribute('srcset') && $nodes[$i]['node']->srcset != '' && htmlspecialchars_decode($translated_words[$i]) != htmlspecialchars_decode($words[$i]['w'])) {
395
  $nodes[$i]['node']->srcset = '';
396
  }
397
  }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === Weglot Translate - Translate your WP website ===
2
  Contributors: remyb92
3
  Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
- Stable tag: 1.7.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -147,6 +147,12 @@ See changelog for upgrade changes.
147
 
148
  == Changelog ==
149
 
 
 
 
 
 
 
150
  = 1.7.1 =
151
  * Fix redirection bug on cart
152
 
1
+ === Translate your WP website - Weglot Translate ===
2
  Contributors: remyb92
3
  Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
4
  Requires at least: 4.5
5
  Tested up to: 4.9
6
+ Stable tag: 1.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
147
 
148
  == Changelog ==
149
 
150
+ = 1.8 =
151
+ * Add new banner and icon
152
+ * improve wc redirection
153
+ * can now translate email
154
+
155
+
156
  = 1.7.1 =
157
  * Fix redirection bug on cart
158
 
weglot.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
  /**
3
  * @package Weglot
4
- * @version 1.7.1
5
  */
6
 
7
  /*
8
- Plugin Name: Weglot Translate
9
- Plugin URI: http://wordpress.org/plugins/Weglot/
10
  Description: Translate your website into multiple languages in minutes without doing any coding. Fully SEO compatible.
11
  Author: Weglot Translate team
12
  Author URI: https://weglot.com/
13
  Text Domain: weglot
14
  Domain Path: /languages/
15
- Version: 1.7.1
16
  */
17
 
18
  /*
@@ -83,7 +83,7 @@ do_action( 'weg_fs_loaded' );
83
 
84
 
85
 
86
- define( 'WEGLOT_VERSION', '1.7.1' );
87
  define( 'WEGLOT_DIR', dirname( __FILE__ ) );
88
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
89
  define( 'WEGLOT_DIRURL', plugin_dir_url( __FILE__ ) );
@@ -174,8 +174,12 @@ class Weglot {
174
  $GLOBALS['text_direction'] = 'ltr';
175
  }
176
 
177
-
178
  add_filter( 'woocommerce_get_cart_url' , array( &$this,'filter_woocommerce_get_cart_url'));
 
 
 
 
 
179
 
180
  $apikey = get_option( 'project_key' );
181
  $this->translator = $apikey ? new \Weglot\Client( $apikey ) : null;
@@ -300,7 +304,7 @@ class Weglot {
300
  <?php
301
  }
302
 
303
- function filter_woocommerce_get_cart_url( $wc_get_page_permalink ) {
304
  if($this->currentlang != $this->original_l) {
305
  return $this->replaceUrl($wc_get_page_permalink, $this->currentlang);
306
  }
@@ -309,6 +313,42 @@ class Weglot {
309
  }
310
  }
311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  public function wg_switcher_creation() {
313
  $button = Weglot::Instance()->returnWidgetCode();
314
  echo wp_kses( $button, $this->getAllowedTags());
@@ -482,6 +522,10 @@ class Weglot {
482
  return register_widget( 'WeglotWidget' );
483
  }
484
 
 
 
 
 
485
  public function treatPage( $final ) {
486
 
487
  $request_uri = $this->request_uri;
@@ -716,7 +760,7 @@ class Weglot {
716
  }
717
 
718
  public function isLinkAFile($current_url) {
719
- $files = array('pdf','rar','doc','docx','jpg','jpeg','png');
720
  foreach ($files as $file) {
721
  if ( WGUtils::endsWith( $current_url,'.'.$file )) {
722
  return true;
@@ -739,6 +783,9 @@ class Weglot {
739
  $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
740
  $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
741
  $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
 
 
 
742
  if ( $l == '' ) {
743
  return $url;
744
  } else {
1
  <?php
2
  /**
3
  * @package Weglot
4
+ * @version 1.8
5
  */
6
 
7
  /*
8
+ Plugin Name: Translate your WP website - Weglot Translate
9
+ Plugin URI: http://wordpress.org/plugins/weglot/
10
  Description: Translate your website into multiple languages in minutes without doing any coding. Fully SEO compatible.
11
  Author: Weglot Translate team
12
  Author URI: https://weglot.com/
13
  Text Domain: weglot
14
  Domain Path: /languages/
15
+ Version: 1.8
16
  */
17
 
18
  /*
83
 
84
 
85
 
86
+ define( 'WEGLOT_VERSION', '1.8' );
87
  define( 'WEGLOT_DIR', dirname( __FILE__ ) );
88
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
89
  define( 'WEGLOT_DIRURL', plugin_dir_url( __FILE__ ) );
174
  $GLOBALS['text_direction'] = 'ltr';
175
  }
176
 
 
177
  add_filter( 'woocommerce_get_cart_url' , array( &$this,'filter_woocommerce_get_cart_url'));
178
+ add_filter( 'woocommerce_get_checkout_url' , array( &$this,'filter_woocommerce_get_cart_url'));
179
+ add_filter( 'woocommerce_get_checkout_order_received_url', array( &$this,'filter_woocommerce_get_checkout_order_received_url'));
180
+
181
+ //add_filter( 'wp_mail' , array( &$this, 'translate_emails'), 10,1);
182
+
183
 
184
  $apikey = get_option( 'project_key' );
185
  $this->translator = $apikey ? new \Weglot\Client( $apikey ) : null;
304
  <?php
305
  }
306
 
307
+ public function filter_woocommerce_get_cart_url( $wc_get_page_permalink ) {
308
  if($this->currentlang != $this->original_l) {
309
  return $this->replaceUrl($wc_get_page_permalink, $this->currentlang);
310
  }
313
  }
314
  }
315
 
316
+ public function filter_woocommerce_get_checkout_order_received_url( $order_received_url, $instance ) {
317
+
318
+ if($this->currentlang != $this->original_l) {
319
+ return $this->replaceUrl($order_received_url, $this->currentlang);
320
+ }
321
+ else {
322
+ if(isset($_SERVER['HTTP_REFERER'])) {
323
+ $l = $this->getLangFromUrl($this->URLToRelative( $_SERVER['HTTP_REFERER']));
324
+ if($l && $l != $this->original_l)
325
+ return $this->replaceUrl($order_received_url, $l);
326
+ }
327
+ return $order_received_url;
328
+ }
329
+ }
330
+
331
+ public function translate_emails($args){
332
+
333
+ $messageAndSubject = "<p>".$args['subject']."</p>".$args['message'];
334
+
335
+ if($this->currentlang != $this->original_l) {
336
+ $messageAndSubjectTranslated = $this->translateEmail($messageAndSubject,$this->currentlang);
337
+ }
338
+ elseif(isset($_SERVER['HTTP_REFERER'])) {
339
+ $l = $this->getLangFromUrl($this->URLToRelative( $_SERVER['HTTP_REFERER']));
340
+ if($l && $l != $this->original_l)
341
+ $messageAndSubjectTranslated = $this->translateEmail($messageAndSubject,$l);
342
+ }
343
+
344
+ if (strpos($messageAndSubjectTranslated, '</p>') !== false) {
345
+ $pos = strpos($messageAndSubjectTranslated, '</p>')+4;
346
+ $args['subject'] = substr($messageAndSubjectTranslated,3,$pos-7);
347
+ $args['message'] = substr($messageAndSubjectTranslated,$pos);
348
+ }
349
+ return $args;
350
+ }
351
+
352
  public function wg_switcher_creation() {
353
  $button = Weglot::Instance()->returnWidgetCode();
354
  echo wp_kses( $button, $this->getAllowedTags());
522
  return register_widget( 'WeglotWidget' );
523
  }
524
 
525
+ public function translateEmail($body,$l) {
526
+ $translatedEmail = $this->translator->translateDomFromTo( $body,$this->original_l,$l );
527
+ return $translatedEmail;
528
+ }
529
  public function treatPage( $final ) {
530
 
531
  $request_uri = $this->request_uri;
760
  }
761
 
762
  public function isLinkAFile($current_url) {
763
+ $files = array('pdf','rar','doc','docx','jpg','jpeg','png','ppt','pptx','xls','zip','mp4');
764
  foreach ($files as $file) {
765
  if ( WGUtils::endsWith( $current_url,'.'.$file )) {
766
  return true;
783
  $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
784
  $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
785
  $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
786
+
787
+ $path = rtrim($path, '/') . '/';
788
+
789
  if ( $l == '' ) {
790
  return $url;
791
  } else {