Weglot Translate – Translate your WP website - Version 3.8

Version Description

(11/10/2022) = * Add: Add ajax checker for woocommerce variations cart popin * Add: Rework switcher. Generate it direclty on render method * Add: Add vary header accept language on redirect * Bug: Fix rtl issue * Bug: Add missing ; on pageviews script * Bug: Send code lang instead of name for wp search query * Bug: Don't translate pdf on original language (woocommerce PDF invoice plugin) * Bug: Prevent add twice weglot_language post meta on woocommerce order * Bug: Prevent block translate if ajax referer are not exclude

Download this release

Release Info

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

Code changes from version 3.7.4 to 3.8

changelog.md CHANGED
@@ -3,6 +3,9 @@
3
 
4
  # Change Log
5
 
 
 
 
6
  ##3.7.3 (05/07/2022) =
7
  * Bugfix: Remove mod_rewrite check with apache_get_module()
8
  * Bugfix: Fix problem with empty switcher from switcher editor
@@ -20,7 +23,7 @@
20
  * Add: Optimize button accessibility
21
  * Add: Pageviews integration
22
  * Add: Add switcher editor integration
23
- * Add: Woocomerce translate all mail
24
  * Add: Do not translate .eps or .txt
25
  * Add: Detect if switcher is child of an iframe and if so, don't display it
26
  * Add: Reduce api call on wp-admin
3
 
4
  # Change Log
5
 
6
+ ##3.7.4 (19/09/2022) =
7
+ * Bugfix: Update CA Root Certificates from Mozilla
8
+
9
  ##3.7.3 (05/07/2022) =
10
  * Bugfix: Remove mod_rewrite check with apache_get_module()
11
  * Bugfix: Fix problem with empty switcher from switcher editor
23
  * Add: Optimize button accessibility
24
  * Add: Pageviews integration
25
  * Add: Add switcher editor integration
26
+ * Add: Woocommerce translate all mail
27
  * Add: Do not translate .eps or .txt
28
  * Add: Detect if switcher is child of an iframe and if so, don't display it
29
  * Add: Reduce api call on wp-admin
composer.json CHANGED
@@ -22,7 +22,7 @@
22
  }
23
  ],
24
  "require": {
25
- "weglot/weglot-php": "^1.5",
26
  "gmulti/morphism-php": "^0.3.0"
27
  },
28
  "repositories": [
@@ -52,5 +52,10 @@
52
  "post-update-cmd": [
53
  "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
54
  ]
55
- }
 
 
 
 
 
56
  }
22
  }
23
  ],
24
  "require": {
25
+ "weglot/weglot-php": "^1.6",
26
  "gmulti/morphism-php": "^0.3.0"
27
  },
28
  "repositories": [
52
  "post-update-cmd": [
53
  "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
54
  ]
55
+ },
56
+ "config": {
57
+ "allow-plugins": {
58
+ "dealerdirect/phpcodesniffer-composer-installer": true
59
+ }
60
+ }
61
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: translate, multilingual, language, translation, localization, multilingual
4
  Requires at least: 4.5
5
  Tested up to: 6.0
6
  Requires PHP: 5.6
7
- Stable tag: 3.7.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -210,8 +210,16 @@ See changelog for upgrade changes.
210
 
211
  == Changelog ==
212
 
213
- = 3.7.4 (19/09/2022) =
214
- * Bugfix: Update CA Root Certificates from Mozilla
 
 
 
 
 
 
 
 
215
 
216
  = Older versions =
217
 
4
  Requires at least: 4.5
5
  Tested up to: 6.0
6
  Requires PHP: 5.6
7
+ Stable tag: 3.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
210
 
211
  == Changelog ==
212
 
213
+ = 3.8 (11/10/2022) =
214
+ * Add: Add ajax checker for woocommerce variations cart popin
215
+ * Add: Rework switcher. Generate it direclty on render method
216
+ * Add: Add vary header accept language on redirect
217
+ * Bug: Fix rtl issue
218
+ * Bug: Add missing ; on pageviews script
219
+ * Bug: Send code lang instead of name for wp search query
220
+ * Bug: Don't translate pdf on original language (woocommerce PDF invoice plugin)
221
+ * Bug: Prevent add twice weglot_language post meta on woocommerce order
222
+ * Bug: Prevent block translate if ajax referer are not exclude
223
 
224
  = Older versions =
225
 
src/actions/front/class-front-enqueue-weglot.php CHANGED
@@ -51,13 +51,14 @@ class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
51
  ?>
52
  <script>
53
  var request = new XMLHttpRequest();
 
54
  var data = JSON.stringify({
55
  url: location.protocol + '//' + location.host + location.pathname,
56
  language: document.getElementsByTagName('html')[0].getAttribute('lang'),
57
  browser_language: (navigator.language || navigator.userLanguage)
58
  }
59
- )
60
- request.open('POST', "https://cdn-api.weglot.com/pageviews?api_key=<?php echo esc_js( $options['api_key'] )?>", true);
61
  request.send(data);
62
  </script>
63
  <?php }
51
  ?>
52
  <script>
53
  var request = new XMLHttpRequest();
54
+ var url = 'ht' + 'tps:' + '//' + 'cdn-api-weglot.com/' + 'pageviews?api_key=' + '<?php echo esc_js( $options['api_key'] )?>';
55
  var data = JSON.stringify({
56
  url: location.protocol + '//' + location.host + location.pathname,
57
  language: document.getElementsByTagName('html')[0].getAttribute('lang'),
58
  browser_language: (navigator.language || navigator.userLanguage)
59
  }
60
+ );
61
+ request.open('POST', url , true);
62
  request.send(data);
63
  </script>
64
  <?php }
src/actions/front/class-search-weglot.php CHANGED
@@ -48,10 +48,10 @@ class Search_Weglot implements Hooks_Interface_Weglot {
48
  }
49
 
50
  /**
 
 
51
  * @see Hooks_Interface_Weglot
52
  *
53
- * @since 2.4.0
54
- * @return void
55
  */
56
  public function hooks() {
57
 
@@ -68,9 +68,10 @@ class Search_Weglot implements Hooks_Interface_Weglot {
68
  }
69
 
70
  /**
71
- * @since 2.4.0
72
  * @param WP_Query $query
 
73
  * @return void
 
74
  */
75
  public function pre_get_posts_translate( $query ) {
76
  if ( ! $query->is_search() ) {
@@ -98,16 +99,17 @@ class Search_Weglot implements Hooks_Interface_Weglot {
98
  return;
99
  }
100
 
101
- set_query_var( $query_vars_check, $this->new_search );
102
  } catch ( \Exception $th ) {
103
  return;
104
  }
105
  }
106
 
107
  /**
108
- * @since 2.4.0
109
  * @param string $string
 
110
  * @return string
 
111
  */
112
  public function get_search_query_translate( $string ) {
113
  return ( $this->old_search ) ? $this->old_search : $string;
48
  }
49
 
50
  /**
51
+ * @return void
52
+ * @since 2.4.0
53
  * @see Hooks_Interface_Weglot
54
  *
 
 
55
  */
56
  public function hooks() {
57
 
68
  }
69
 
70
  /**
 
71
  * @param WP_Query $query
72
+ *
73
  * @return void
74
+ * @since 2.4.0
75
  */
76
  public function pre_get_posts_translate( $query ) {
77
  if ( ! $query->is_search() ) {
99
  return;
100
  }
101
 
102
+ $query->set( $query_vars_check, $this->new_search ); //phpcs:ignore
103
  } catch ( \Exception $th ) {
104
  return;
105
  }
106
  }
107
 
108
  /**
 
109
  * @param string $string
110
+ *
111
  * @return string
112
+ * @since 2.4.0
113
  */
114
  public function get_search_query_translate( $string ) {
115
  return ( $this->old_search ) ? $this->old_search : $string;
src/services/class-generate-switcher-service-weglot.php CHANGED
@@ -90,7 +90,7 @@ class Generate_Switcher_Service_Weglot {
90
 
91
  /**
92
  * @param string $dom the final HTML.
93
- * @param array $switchers the array of switchers from settings.
94
  *
95
  * @return string
96
  * @since 2.3.0
@@ -100,31 +100,27 @@ class Generate_Switcher_Service_Weglot {
100
  $original_language = $this->language_services->get_original_language()->getInternalCode();
101
  $current_language = $this->request_url_services->get_current_language()->getInternalCode();
102
 
103
- // In original language, as we don't use the PHP lib, we have not yet placed the custom switchers in the DOM so we need to use simple DOM here.
104
- if ( $original_language === $current_language || ! $this->request_url_services->is_eligible_url() ) {
105
- // simple_html_dom.
106
- $dom = \WGSimpleHtmlDom\str_get_html(
107
- $dom,
108
- true,
109
- true,
110
- WG_DEFAULT_TARGET_CHARSET,
111
- false
112
- );
113
-
114
- $custom_switchers = new CustomSwitchersFormatter( $dom, $switchers );
115
- $dom = $custom_switchers->getDom();
116
- $dom = $dom->save();
117
- }
118
 
119
  // Place the button if not in the page.
120
  $find_location = false;
121
  foreach ( $switchers as $switcher ) {
122
 
123
- $button_html = $this->button_services->get_html( 'weglot-custom-switcher', $switcher );
124
- $location = $this->option_services->get_switcher_editor_option( 'location', $switcher );
125
-
126
  if ( ! empty( $location ) ) {
127
- $key = $location['target'] . ( ! empty( $location['sibling'] ) ? ' ' . $location['sibling'] : '' );
 
128
  if ( strpos( $dom, '<div data-wg-position="' . $key . '"></div>' ) !== false ) {
129
  $dom = str_replace( '<div data-wg-position="' . $key . '"></div>', $button_html, $dom );
130
  $find_location = true;
@@ -135,6 +131,11 @@ class Generate_Switcher_Service_Weglot {
135
  $dom = str_replace( '<div data-wg-position="' . $key . '" data-wg-ajax="true"></div>', $button_ajax_html, $dom );
136
  $find_location = true;
137
  }
 
 
 
 
 
138
  }
139
  }
140
  if ( ! $find_location ) {
@@ -160,6 +161,7 @@ class Generate_Switcher_Service_Weglot {
160
  }
161
 
162
  $dom = ! empty( $dom_with_switchers ) ? $dom_with_switchers : $this->render_default_button( $dom );
 
163
  return apply_filters( 'weglot_generate_switcher_from_dom', $dom );
164
  }
165
  }
90
 
91
  /**
92
  * @param string $dom the final HTML.
93
+ * @param array $switchers the array of switchers from settings.
94
  *
95
  * @return string
96
  * @since 2.3.0
100
  $original_language = $this->language_services->get_original_language()->getInternalCode();
101
  $current_language = $this->request_url_services->get_current_language()->getInternalCode();
102
 
103
+ // get translate dom and add custom switcher in.
104
+ $dom = \WGSimpleHtmlDom\str_get_html(
105
+ $dom,
106
+ true,
107
+ true,
108
+ WG_DEFAULT_TARGET_CHARSET,
109
+ false
110
+ );
111
+
112
+ $custom_switchers = new CustomSwitchersFormatter( $dom, $switchers );
113
+ $dom = $custom_switchers->getDom();
114
+ $dom = $dom->save();
 
 
 
115
 
116
  // Place the button if not in the page.
117
  $find_location = false;
118
  foreach ( $switchers as $switcher ) {
119
 
120
+ $location = $this->option_services->get_switcher_editor_option( 'location', $switcher );
 
 
121
  if ( ! empty( $location ) ) {
122
+ $button_html = $this->button_services->get_html( 'weglot-custom-switcher', $switcher );
123
+ $key = $location['target'] . ( ! empty( $location['sibling'] ) ? ' ' . $location['sibling'] : '' );
124
  if ( strpos( $dom, '<div data-wg-position="' . $key . '"></div>' ) !== false ) {
125
  $dom = str_replace( '<div data-wg-position="' . $key . '"></div>', $button_html, $dom );
126
  $find_location = true;
131
  $dom = str_replace( '<div data-wg-position="' . $key . '" data-wg-ajax="true"></div>', $button_ajax_html, $dom );
132
  $find_location = true;
133
  }
134
+ } else {
135
+ // if the location is empty we place the button at default position.
136
+ $button_html = $this->button_services->get_html( 'weglot-default', $switcher );
137
+ $dom = str_replace( '</body>', $button_html, $dom );
138
+ $find_location = true;
139
  }
140
  }
141
  if ( ! $find_location ) {
161
  }
162
 
163
  $dom = ! empty( $dom_with_switchers ) ? $dom_with_switchers : $this->render_default_button( $dom );
164
+
165
  return apply_filters( 'weglot_generate_switcher_from_dom', $dom );
166
  }
167
  }
src/services/class-language-service-weglot.php CHANGED
@@ -87,7 +87,7 @@ class Language_Service_Weglot {
87
  * @param $external_code
88
  * @param $english_name
89
  * @param $local_name
90
- * @param bool $is_rtl
91
  *
92
  * @return array
93
  */
@@ -113,21 +113,22 @@ class Language_Service_Weglot {
113
  $original_language = $this->get_original_language();
114
 
115
  if ( ! empty( $this->get_original_language_name_custom() ) ) {
116
- $this->languages = $this->add_language( $original_language->getInternalCode(), $original_language->getExternalCode(), $this->get_original_language_name_custom(), $this->get_original_language_name_custom() );
117
  }
118
 
119
  foreach ( $destination_languages as $d ) {
120
  $language_data = $this->languages->getCode( $d['language_to'] );
121
  if ( ! $language_data ) {
122
- $this->languages = $this->add_language( $d['language_to'], $d['custom_code'], $d['custom_name'], $d['custom_local_name'] );
123
  } else {
124
  $external_code = isset( $d['custom_code'] ) ? $d['custom_code'] : $language_data->getExternalCode();
125
  $custom_local_name = isset( $d['custom_name'] ) ? $d['custom_name'] : $language_data->getLocalName(); // TODO: remove after core fixes bug.
126
  $custom_local_name = isset( $d['custom_local_name'] ) ? $d['custom_local_name'] : $custom_local_name;
127
  $custom_name = isset( $d['custom_name'] ) ? $d['custom_name'] : $language_data->getEnglishName();
128
- $this->languages = $this->add_language( $d['language_to'], $external_code, $custom_name, $custom_local_name ); // côté core : il faut que le nom qui change soit le custom_local_name.
129
  }
130
  }
 
131
  return $this->languages;
132
  }
133
 
87
  * @param $external_code
88
  * @param $english_name
89
  * @param $local_name
90
+ * @param bool $is_rtl
91
  *
92
  * @return array
93
  */
113
  $original_language = $this->get_original_language();
114
 
115
  if ( ! empty( $this->get_original_language_name_custom() ) ) {
116
+ $this->languages = $this->add_language( $original_language->getInternalCode(), $original_language->getExternalCode(), $this->get_original_language_name_custom(), $this->get_original_language_name_custom(), $original_language->isRtl() );
117
  }
118
 
119
  foreach ( $destination_languages as $d ) {
120
  $language_data = $this->languages->getCode( $d['language_to'] );
121
  if ( ! $language_data ) {
122
+ $this->languages = $this->add_language( $d['language_to'], $d['custom_code'], $d['custom_name'], $d['custom_local_name'], $language_data->isRtl() );
123
  } else {
124
  $external_code = isset( $d['custom_code'] ) ? $d['custom_code'] : $language_data->getExternalCode();
125
  $custom_local_name = isset( $d['custom_name'] ) ? $d['custom_name'] : $language_data->getLocalName(); // TODO: remove after core fixes bug.
126
  $custom_local_name = isset( $d['custom_local_name'] ) ? $d['custom_local_name'] : $custom_local_name;
127
  $custom_name = isset( $d['custom_name'] ) ? $d['custom_name'] : $language_data->getEnglishName();
128
+ $this->languages = $this->add_language( $d['language_to'], $external_code, $custom_name, $custom_local_name, $language_data->isRtl() ); // côté core : il faut que le nom qui change soit le custom_local_name.
129
  }
130
  }
131
+
132
  return $this->languages;
133
  }
134
 
src/services/class-redirect-service-weglot.php CHANGED
@@ -174,7 +174,9 @@ class Redirect_Service_Weglot {
174
  if ( ! $this->request_url_services->get_weglot_url()->getForLanguage( $best_language, false ) ){
175
  return;
176
  }
 
177
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $best_language, true ) );
 
178
  header( "Location: $url_auto_redirect", true, 302 );
179
  exit();
180
  }
@@ -190,6 +192,7 @@ class Redirect_Service_Weglot {
190
  return;
191
  }
192
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $fallback_language, true ) );
 
193
  header( "Location: $url_auto_redirect", true, 302 );
194
  exit();
195
  }
174
  if ( ! $this->request_url_services->get_weglot_url()->getForLanguage( $best_language, false ) ){
175
  return;
176
  }
177
+
178
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $best_language, true ) );
179
+ header('Vary: Accept-Language');
180
  header( "Location: $url_auto_redirect", true, 302 );
181
  exit();
182
  }
192
  return;
193
  }
194
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $fallback_language, true ) );
195
+ header('Vary: Accept-Language');
196
  header( "Location: $url_auto_redirect", true, 302 );
197
  exit();
198
  }
src/services/class-translate-service-weglot.php CHANGED
@@ -136,10 +136,11 @@ class Translate_Service_Weglot {
136
  if ( http_response_code() == 404 ) {
137
  $excluded_urls = $this->option_services->get_exclude_urls();
138
  foreach ( $excluded_urls as $item ) {
139
- if($item[0] === '^/404$'){
140
  return true;
141
  }
142
  }
 
143
  return false;
144
  } else {
145
  return false;
@@ -155,6 +156,7 @@ class Translate_Service_Weglot {
155
  * @see weglot_init / ob_start
156
  */
157
  public function weglot_treat_page( $content ) {
 
158
  if ( empty( $content ) ) {
159
  return $content;
160
  }
@@ -167,25 +169,29 @@ class Translate_Service_Weglot {
167
  $type = ( Helper_Json_Inline_Weglot::is_xml( $content ) ) ? 'xml' : 'html';
168
  }
169
 
170
- $type = apply_filters( 'weglot_type_treat_page', $type );
171
  $active_translation = apply_filters( 'weglot_active_translation', true );
172
- $canonical = $this->get_canonical_url_from_content( $content );
173
 
174
  // No need to translate but prepare new dom with button.
175
  if (
176
  $this->current_language === $this->original_language
177
  || ! $active_translation
178
  || $this->check_404_exclusion_before_treat()
179
- || $this->check_ajax_exclusion_before_treat()
180
- || ! $this->request_url_services->get_weglot_url()->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
181
-
182
- // if type is xml we render the content without treatment.
183
- if($type === 'xml'){
184
- return $content;
185
- }else{
186
- return $this->weglot_render_dom( $content, $canonical );
 
 
 
 
 
187
  }
188
-
189
  }
190
 
191
  $parser = $this->parser_services->get_parser();
@@ -196,23 +202,18 @@ class Translate_Service_Weglot {
196
  $extra_keys = apply_filters( 'weglot_add_json_keys', array() );
197
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, $extra_keys );
198
  $translated_content = wp_json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
199
-
200
  return apply_filters( 'weglot_json_treat_page', $translated_content );
201
  case 'xml':
202
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, array(), $canonical );
203
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
204
-
205
  return apply_filters( 'weglot_xml_treat_page', $translated_content );
206
  case 'html':
207
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, array(), $canonical );
208
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
209
-
210
  return $this->weglot_render_dom( $translated_content, $canonical );
211
  default:
212
  $name_filter = sprintf( 'weglot_%s_treat_page', $type );
213
-
214
  return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
215
-
216
  }
217
  } catch ( ApiError $e ) {
218
  if ( 'json' !== $type ) {
@@ -278,9 +279,10 @@ class Translate_Service_Weglot {
278
 
279
  // update canonical if page excluded page.
280
  if ( ! $current_url->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
281
- $dom = preg_replace( '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', '<link rel="canonical" href="' . esc_url ( $current_url->getForLanguage( $this->language_services->get_original_language() ) ) . '"', $dom );
282
  }
283
  }
 
284
  return apply_filters( 'weglot_render_dom', $dom );
285
  }
286
  }
136
  if ( http_response_code() == 404 ) {
137
  $excluded_urls = $this->option_services->get_exclude_urls();
138
  foreach ( $excluded_urls as $item ) {
139
+ if ( $item[0] === '^/404$' ) {
140
  return true;
141
  }
142
  }
143
+
144
  return false;
145
  } else {
146
  return false;
156
  * @see weglot_init / ob_start
157
  */
158
  public function weglot_treat_page( $content ) {
159
+
160
  if ( empty( $content ) ) {
161
  return $content;
162
  }
169
  $type = ( Helper_Json_Inline_Weglot::is_xml( $content ) ) ? 'xml' : 'html';
170
  }
171
 
172
+ $type = apply_filters( 'weglot_type_treat_page', $type );
173
  $active_translation = apply_filters( 'weglot_active_translation', true );
174
+ $canonical = $this->get_canonical_url_from_content( $content );
175
 
176
  // No need to translate but prepare new dom with button.
177
  if (
178
  $this->current_language === $this->original_language
179
  || ! $active_translation
180
  || $this->check_404_exclusion_before_treat()
181
+ || ! $this->request_url_services->get_weglot_url()->getForLanguage( $this->request_url_services->get_current_language(), false )
182
+ ) {
183
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
184
+ if ( ! $this->request_url_services->create_url_object( wp_get_referer() )->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
185
+ // do nothing because the ajax referer are not exclude!
186
+ }
187
+ } else {
188
+ // if type is xml we render the content without treatment.
189
+ if ( $type === 'xml' ) {
190
+ return $content;
191
+ } else {
192
+ return $this->weglot_render_dom( $content, $canonical );
193
+ }
194
  }
 
195
  }
196
 
197
  $parser = $this->parser_services->get_parser();
202
  $extra_keys = apply_filters( 'weglot_add_json_keys', array() );
203
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, $extra_keys );
204
  $translated_content = wp_json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
 
205
  return apply_filters( 'weglot_json_treat_page', $translated_content );
206
  case 'xml':
207
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, array(), $canonical );
208
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
 
209
  return apply_filters( 'weglot_xml_treat_page', $translated_content );
210
  case 'html':
211
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, array(), $canonical );
212
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
 
213
  return $this->weglot_render_dom( $translated_content, $canonical );
214
  default:
215
  $name_filter = sprintf( 'weglot_%s_treat_page', $type );
 
216
  return apply_filters( $name_filter, $content, $parser, $this->original_language, $this->current_language );
 
217
  }
218
  } catch ( ApiError $e ) {
219
  if ( 'json' !== $type ) {
279
 
280
  // update canonical if page excluded page.
281
  if ( ! $current_url->getForLanguage( $this->request_url_services->get_current_language(), false ) ) {
282
+ $dom = preg_replace( '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/', '<link rel="canonical" href="' . esc_url( $current_url->getForLanguage( $this->language_services->get_original_language() ) ) . '"', $dom );
283
  }
284
  }
285
+
286
  return apply_filters( 'weglot_render_dom', $dom );
287
  }
288
  }
src/third/woocommerce/class-wc-mail-weglot.php CHANGED
@@ -127,8 +127,12 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
127
  return;
128
  }
129
 
130
- $current_language = $this->request_url_services->get_current_language()->getExternalCode();
131
- add_post_meta( $order_id, 'weglot_language', $current_language );
 
 
 
 
132
 
133
  return $order_id;
134
  }
127
  return;
128
  }
129
 
130
+ $woocommerce_order_language = get_post_meta( $order_id, 'weglot_language', true );
131
+
132
+ if ( ! $woocommerce_order_language ) {
133
+ $current_language = $this->request_url_services->get_current_language()->getExternalCode();
134
+ add_post_meta( $order_id, 'weglot_language', $current_language );
135
+ }
136
 
137
  return $order_id;
138
  }
src/third/woocommerce/regexcheckers/class-wc-json-add-cart-variations.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Third\Woocommerce\Regexcheckers;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use Weglot\Parser\Check\Regex\RegexChecker;
10
+ use Weglot\Util\SourceType;
11
+
12
+
13
+ /**
14
+ * @since 2.0.7
15
+ */
16
+ class Wc_Json_Add_Cart_Variations {
17
+
18
+ const REGEX = '#var wc_add_to_cart_variation_params = (.*);#';
19
+
20
+ const TYPE = SourceType::SOURCE_JSON;
21
+
22
+ const VAR_NUMBER = 1;
23
+
24
+ public static $KEYS = array('i18n_no_matching_variations_text', 'i18n_make_a_selection_text', 'i18n_unavailable_text');
25
+ }
src/third/woocommercepdf/class-wcpdf-weglot.php CHANGED
@@ -44,10 +44,10 @@ class WCPDF_Weglot implements Hooks_Interface_Weglot {
44
  * @since 3.7
45
  */
46
  public function __construct() {
47
- $this->wcpdf_active_services = weglot_get_service( 'Wcpdf_Active' );
48
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
49
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
50
- $this->pdf_translate_services = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
51
  }
52
 
53
  /**
@@ -72,21 +72,25 @@ class WCPDF_Weglot implements Hooks_Interface_Weglot {
72
 
73
  $translate_pdf = apply_filters( 'weglot_translate_pdf', false );
74
 
75
- if( !$translate_pdf ){
76
  return $dompdf;
77
  }
78
 
79
- if( ! empty( sanitize_key($_GET['order_ids'] ))){ // phpcs:ignore
80
- $order_id = sanitize_key($_GET['order_ids']); // phpcs:ignore
81
  }
82
 
83
- if( empty( $order_id )){
84
  return $dompdf;
85
  }
86
 
87
  $woocommerce_order_language = get_post_meta( $order_id, 'weglot_language', true ); // phpcs:ignore
88
 
89
- $_dompdf = clone $dompdf;
 
 
 
 
90
  unset( $dompdf );
91
  $_dompdf_options = $_dompdf->getOptions();
92
  $_dompdf_paper_size = $_dompdf->getPaperSize();
@@ -96,7 +100,7 @@ class WCPDF_Weglot implements Hooks_Interface_Weglot {
96
  $_dompdf->render();
97
  unset( $_dompdf );
98
 
99
- $dompdf = new \Dompdf\Dompdf( $_dompdf_options );
100
  $translated_pdf = $this->pdf_translate_services->translate_pdf( $html, $woocommerce_order_language );
101
 
102
  $dompdf->loadHtml( $translated_pdf['content'] );
44
  * @since 3.7
45
  */
46
  public function __construct() {
47
+ $this->wcpdf_active_services = weglot_get_service( 'Wcpdf_Active' );
48
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
49
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
50
+ $this->pdf_translate_services = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
51
  }
52
 
53
  /**
72
 
73
  $translate_pdf = apply_filters( 'weglot_translate_pdf', false );
74
 
75
+ if ( ! $translate_pdf ) {
76
  return $dompdf;
77
  }
78
 
79
+ if ( ! empty( sanitize_key( $_GET['order_ids'] ) ) ) { // phpcs:ignore
80
+ $order_id = sanitize_key( $_GET['order_ids'] ); // phpcs:ignore
81
  }
82
 
83
+ if ( empty( $order_id ) ) {
84
  return $dompdf;
85
  }
86
 
87
  $woocommerce_order_language = get_post_meta( $order_id, 'weglot_language', true ); // phpcs:ignore
88
 
89
+ if ( $woocommerce_order_language == weglot_get_original_language() ) {
90
+ return $dompdf;
91
+ }
92
+
93
+ $_dompdf = clone $dompdf;
94
  unset( $dompdf );
95
  $_dompdf_options = $_dompdf->getOptions();
96
  $_dompdf_paper_size = $_dompdf->getPaperSize();
100
  $_dompdf->render();
101
  unset( $_dompdf );
102
 
103
+ $dompdf = new \Dompdf\Dompdf( $_dompdf_options );
104
  $translated_pdf = $this->pdf_translate_services->translate_pdf( $html, $woocommerce_order_language );
105
 
106
  $dompdf->loadHtml( $translated_pdf['content'] );
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit13bf7c2aa976145ea50a03f1d032bd06::getLoader();
vendor/composer/InstalledVersions.php CHANGED
@@ -30,7 +30,7 @@ private static $installed = array (
30
  'aliases' =>
31
  array (
32
  ),
33
- 'reference' => '98c239a5acaaf54105ecd46202cd654340f3d89c',
34
  'name' => 'weglot/translate-wordpress',
35
  ),
36
  'versions' =>
@@ -69,7 +69,7 @@ private static $installed = array (
69
  'aliases' =>
70
  array (
71
  ),
72
- 'reference' => '98c239a5acaaf54105ecd46202cd654340f3d89c',
73
  ),
74
  'weglot/translation-definitions' =>
75
  array (
@@ -82,12 +82,12 @@ private static $installed = array (
82
  ),
83
  'weglot/weglot-php' =>
84
  array (
85
- 'pretty_version' => '1.5',
86
- 'version' => '1.5.0.0',
87
  'aliases' =>
88
  array (
89
  ),
90
- 'reference' => '82b2b7381a925ae0d7b868cf9abf187beeeabc1e',
91
  ),
92
  ),
93
  );
30
  'aliases' =>
31
  array (
32
  ),
33
+ 'reference' => '55907df54ca367d3e146074cedc8a0a86980c2fc',
34
  'name' => 'weglot/translate-wordpress',
35
  ),
36
  'versions' =>
69
  'aliases' =>
70
  array (
71
  ),
72
+ 'reference' => '55907df54ca367d3e146074cedc8a0a86980c2fc',
73
  ),
74
  'weglot/translation-definitions' =>
75
  array (
82
  ),
83
  'weglot/weglot-php' =>
84
  array (
85
+ 'pretty_version' => '1.6',
86
+ 'version' => '1.6.0.0',
87
  'aliases' =>
88
  array (
89
  ),
90
+ 'reference' => 'e5fb5b78ecb40219ca86a91c2ed122b1b130bdad',
91
  ),
92
  ),
93
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d
6
  {
7
  private static $loader;
8
 
@@ -24,15 +24,15 @@ class ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
- spl_autoload_register(array('ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
- spl_autoload_unregister(array('ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
- call_user_func(\Composer\Autoload\ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
@@ -53,19 +53,19 @@ class ComposerAutoloaderInit92257254c6fd8e45e5db2df9f00b1b3d
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
- $includeFiles = Composer\Autoload\ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
- composerRequire92257254c6fd8e45e5db2df9f00b1b3d($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
- function composerRequire92257254c6fd8e45e5db2df9f00b1b3d($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit13bf7c2aa976145ea50a03f1d032bd06
6
  {
7
  private static $loader;
8
 
24
 
25
  require __DIR__ . '/platform_check.php';
26
 
27
+ spl_autoload_register(array('ComposerAutoloaderInit13bf7c2aa976145ea50a03f1d032bd06', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29
+ spl_autoload_unregister(array('ComposerAutoloaderInit13bf7c2aa976145ea50a03f1d032bd06', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
  require __DIR__ . '/autoload_static.php';
34
 
35
+ call_user_func(\Composer\Autoload\ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
+ $includeFiles = Composer\Autoload\ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
+ composerRequire13bf7c2aa976145ea50a03f1d032bd06($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
+ function composerRequire13bf7c2aa976145ea50a03f1d032bd06($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -66,10 +66,10 @@ class ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d
66
  public static function getInitializer(ClassLoader $loader)
67
  {
68
  return \Closure::bind(function () use ($loader) {
69
- $loader->prefixLengthsPsr4 = ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::$prefixLengthsPsr4;
70
- $loader->prefixDirsPsr4 = ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::$prefixDirsPsr4;
71
- $loader->prefixesPsr0 = ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::$prefixesPsr0;
72
- $loader->classMap = ComposerStaticInit92257254c6fd8e45e5db2df9f00b1b3d::$classMap;
73
 
74
  }, null, ClassLoader::class);
75
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
66
  public static function getInitializer(ClassLoader $loader)
67
  {
68
  return \Closure::bind(function () use ($loader) {
69
+ $loader->prefixLengthsPsr4 = ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::$prefixLengthsPsr4;
70
+ $loader->prefixDirsPsr4 = ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::$prefixDirsPsr4;
71
+ $loader->prefixesPsr0 = ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::$prefixesPsr0;
72
+ $loader->classMap = ComposerStaticInit13bf7c2aa976145ea50a03f1d032bd06::$classMap;
73
 
74
  }, null, ClassLoader::class);
75
  }
vendor/composer/installed.json CHANGED
@@ -190,17 +190,17 @@
190
  },
191
  {
192
  "name": "weglot/weglot-php",
193
- "version": "1.5",
194
- "version_normalized": "1.5.0.0",
195
  "source": {
196
  "type": "git",
197
  "url": "git@github.com:weglot/weglot-php.git",
198
- "reference": "82b2b7381a925ae0d7b868cf9abf187beeeabc1e"
199
  },
200
  "dist": {
201
  "type": "zip",
202
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/82b2b7381a925ae0d7b868cf9abf187beeeabc1e",
203
- "reference": "82b2b7381a925ae0d7b868cf9abf187beeeabc1e",
204
  "shasum": ""
205
  },
206
  "require": {
@@ -213,7 +213,7 @@
213
  "codeception/codeception": "^2.4",
214
  "vlucas/phpdotenv": "^2.4"
215
  },
216
- "time": "2022-09-19T12:03:47+00:00",
217
  "type": "library",
218
  "installation-source": "dist",
219
  "autoload": {
190
  },
191
  {
192
  "name": "weglot/weglot-php",
193
+ "version": "1.6",
194
+ "version_normalized": "1.6.0.0",
195
  "source": {
196
  "type": "git",
197
  "url": "git@github.com:weglot/weglot-php.git",
198
+ "reference": "e5fb5b78ecb40219ca86a91c2ed122b1b130bdad"
199
  },
200
  "dist": {
201
  "type": "zip",
202
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/e5fb5b78ecb40219ca86a91c2ed122b1b130bdad",
203
+ "reference": "e5fb5b78ecb40219ca86a91c2ed122b1b130bdad",
204
  "shasum": ""
205
  },
206
  "require": {
213
  "codeception/codeception": "^2.4",
214
  "vlucas/phpdotenv": "^2.4"
215
  },
216
+ "time": "2022-09-27T14:59:28+00:00",
217
  "type": "library",
218
  "installation-source": "dist",
219
  "autoload": {
vendor/composer/installed.php CHANGED
@@ -6,7 +6,7 @@
6
  'aliases' =>
7
  array (
8
  ),
9
- 'reference' => '98c239a5acaaf54105ecd46202cd654340f3d89c',
10
  'name' => 'weglot/translate-wordpress',
11
  ),
12
  'versions' =>
@@ -45,7 +45,7 @@
45
  'aliases' =>
46
  array (
47
  ),
48
- 'reference' => '98c239a5acaaf54105ecd46202cd654340f3d89c',
49
  ),
50
  'weglot/translation-definitions' =>
51
  array (
@@ -58,12 +58,12 @@
58
  ),
59
  'weglot/weglot-php' =>
60
  array (
61
- 'pretty_version' => '1.5',
62
- 'version' => '1.5.0.0',
63
  'aliases' =>
64
  array (
65
  ),
66
- 'reference' => '82b2b7381a925ae0d7b868cf9abf187beeeabc1e',
67
  ),
68
  ),
69
  );
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => '55907df54ca367d3e146074cedc8a0a86980c2fc',
10
  'name' => 'weglot/translate-wordpress',
11
  ),
12
  'versions' =>
45
  'aliases' =>
46
  array (
47
  ),
48
+ 'reference' => '55907df54ca367d3e146074cedc8a0a86980c2fc',
49
  ),
50
  'weglot/translation-definitions' =>
51
  array (
58
  ),
59
  'weglot/weglot-php' =>
60
  array (
61
+ 'pretty_version' => '1.6',
62
+ 'version' => '1.6.0.0',
63
  'aliases' =>
64
  array (
65
  ),
66
+ 'reference' => 'e5fb5b78ecb40219ca86a91c2ed122b1b130bdad',
67
  ),
68
  ),
69
  );
vendor/weglot/weglot-php/src/Client/HttpClient/CurlClient.php CHANGED
@@ -283,6 +283,7 @@ class CurlClient implements ClientInterface
283
  $options[CURLOPT_TIMEOUT] = $this->getTimeout();
284
  $options[CURLOPT_HTTPHEADER] = $headers;
285
  $options[CURLOPT_SSL_VERIFYPEER] = true;
 
286
  $options[CURLOPT_CAINFO] = __DIR__ . '/../../../data/ca-certificates.crt';
287
 
288
  return $options;
283
  $options[CURLOPT_TIMEOUT] = $this->getTimeout();
284
  $options[CURLOPT_HTTPHEADER] = $headers;
285
  $options[CURLOPT_SSL_VERIFYPEER] = true;
286
+ $options[CURLOPT_CAPATH] = __DIR__ . '/../../../data/';
287
  $options[CURLOPT_CAINFO] = __DIR__ . '/../../../data/ca-certificates.crt';
288
 
289
  return $options;
weglot.php CHANGED
@@ -7,7 +7,7 @@ Author: Weglot Translate team
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
- Version: 3.7.4
11
  */
12
 
13
  /**
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
- define( 'WEGLOT_VERSION', '3.7.4' );
26
  define( 'WEGLOT_PHP_MIN', '5.6' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
+ Version: 3.8
11
  */
12
 
13
  /**
22
  define( 'WEGLOT_NAME', 'Weglot' );
23
  define( 'WEGLOT_SLUG', 'weglot-translate' );
24
  define( 'WEGLOT_OPTION_GROUP', 'group-weglot-translate' );
25
+ define( 'WEGLOT_VERSION', '3.8' );
26
  define( 'WEGLOT_PHP_MIN', '5.6' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );