TranslatePress – Translate Multilingual sites - Version 1.1.2

Version Description

We now make sure that all forms when submitted redirect to the correct language Fixed an issue with missing slash from language switcher Fixed an issue where we were not redirecting to the correct url slug when switching languages Fixed a possible notice inside the get_language_names function Fixed html breaking because of unescaped quotes in translated meta content Removed a special character from the full_trim function that was causing some strings to not be selectable for translation

Download this release

Release Info

Developer madalin.ungureanu
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

assets/js/trp-editor-script.js CHANGED
@@ -1344,6 +1344,7 @@ jQuery( function(){
1344
  }, 2000 );
1345
  }
1346
  });
 
1347
  });
1348
 
1349
 
1344
  }, 2000 );
1345
  }
1346
  });
1347
+
1348
  });
1349
 
1350
 
class-translate-press.php CHANGED
@@ -39,7 +39,7 @@ class TRP_Translate_Press{
39
  define( 'TRP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
40
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
42
- define( 'TRP_PLUGIN_VERSION', '1.1.1' );
43
 
44
  $this->load_dependencies();
45
  $this->initialize_components();
@@ -129,7 +129,9 @@ class TRP_Translate_Press{
129
  $this->loader->add_action( 'admin_init', $this->translation_render, 'start_output_buffer' );
130
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
131
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_preview_on_url_redirect', 99, 2 );
132
- $this->loader->add_filter( 'trp_before_translate_content', $this->translation_render, 'force_preview_on_url_in_ajax' );
 
 
133
 
134
 
135
  $this->loader->add_action( 'wp_enqueue_scripts', $this->language_switcher, 'enqueue_language_switcher_scripts' );
39
  define( 'TRP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
40
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
42
+ define( 'TRP_PLUGIN_VERSION', '1.1.2' );
43
 
44
  $this->load_dependencies();
45
  $this->initialize_components();
129
  $this->loader->add_action( 'admin_init', $this->translation_render, 'start_output_buffer' );
130
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
131
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_preview_on_url_redirect', 99, 2 );
132
+ $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_language_on_form_url_redirect', 99, 2 );
133
+ $this->loader->add_filter( 'trp_before_translate_content', $this->translation_render, 'force_preview_on_url_in_ajax', 10 );
134
+ $this->loader->add_filter( 'trp_before_translate_content', $this->translation_render, 'force_form_language_on_url_in_ajax', 20 );
135
 
136
 
137
  $this->loader->add_action( 'wp_enqueue_scripts', $this->language_switcher, 'enqueue_language_switcher_scripts' );
includes/class-languages.php CHANGED
@@ -125,7 +125,9 @@ class TRP_Languages{
125
  $return = array();
126
  $languages = $this->get_languages( $english_or_native_name );
127
  foreach ( $language_codes as $language_code ){
128
- $return[$language_code] = $languages[$language_code];
 
 
129
  }
130
 
131
  return $return;
125
  $return = array();
126
  $languages = $this->get_languages( $english_or_native_name );
127
  foreach ( $language_codes as $language_code ){
128
+ if( isset( $languages[$language_code] ) ) {
129
+ $return[$language_code] = $languages[$language_code];
130
+ }
131
  }
132
 
133
  return $return;
includes/class-query.php CHANGED
@@ -33,8 +33,9 @@ class TRP_Query{
33
  * @return string Trimmed string.
34
  */
35
  protected function full_trim( $word ) {
36
-
37
- $word = trim($word," \t\n\r\0\x0B\xA0�" );
 
38
 
39
  // make sure to skip weird characters
40
  if ( htmlentities( $word ) == "" ){
33
  * @return string Trimmed string.
34
  */
35
  protected function full_trim( $word ) {
36
+ /* apparently the � char in the trim function turns some strings in an empty string so they can't be translated but I don't really know if we should remove it completely */
37
+ //$word = trim($word," \t\n\r\0\x0B\xA0�" );
38
+ $word = trim($word," \t\n\r\0\x0B\xA0" );
39
 
40
  // make sure to skip weird characters
41
  if ( htmlentities( $word ) == "" ){
includes/class-translation-render.php CHANGED
@@ -57,14 +57,18 @@ class TRP_Translation_Render{
57
  }
58
 
59
  /**
60
- * Language to translate into.
 
 
61
  *
62
  * @return string Language code.
63
  */
64
- protected function get_language(){
65
  global $TRP_LANGUAGE;
66
  if ( in_array( $TRP_LANGUAGE, $this->settings['translation-languages'] ) ) {
67
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ){
 
 
68
  if ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) {
69
  if( count( $this->settings['publish-languages'] ) > 1 ){
70
  foreach ($this->settings['translation-languages'] as $language) {
@@ -92,7 +96,9 @@ class TRP_Translation_Render{
92
  * @return string Trimmed string.
93
  */
94
  public function full_trim( $word ) {
95
- $word = trim($word," \t\n\r\0\x0B\xA0�".chr( 194 ) . chr( 160 ) );
 
 
96
  if ( htmlentities( $word ) == "" || strip_tags( $word ) == "" || trim ($word, " \t\n\r\0\x0B\xA0�.,/`~!@#\$€£%^&*():;-_=+[]{}\\|?/<>1234567890'\"" ) == '' ){
97
  $word = '';
98
  }
@@ -206,11 +212,14 @@ class TRP_Translation_Render{
206
  * @return string Translated HTML page.
207
  */
208
  public function translate_page( $output ){
 
 
209
  if ( strlen( $output ) < 1 ){
210
  return $output;
211
  }
 
212
  global $TRP_LANGUAGE;
213
- $language_code = $this->get_language();
214
  if ($language_code === false) {
215
  return $output;
216
  }
@@ -224,8 +233,6 @@ class TRP_Translation_Render{
224
  return $output;
225
  }
226
 
227
- $output = apply_filters('trp_before_translate_content', $output);
228
-
229
  //check if we have a json response
230
  if (is_array($json_array = json_decode($output, true))) {
231
  if (!empty($json_array)) {
@@ -407,7 +414,7 @@ class TRP_Translation_Render{
407
  ),
408
  'meta_desc' => array(
409
  'accessor' => 'content',
410
- 'attribute' => false
411
  ),
412
  'post_slug' => array(
413
  'accessor' => 'content',
@@ -447,7 +454,7 @@ class TRP_Translation_Render{
447
  if ( strpos ( $nodes[$i]['node']->getAttribute( $accessor ), $translateable_string ) === false ){
448
  $translateable_string = $alternate_translateable_string;
449
  }
450
- $nodes[$i]['node']->setAttribute( $accessor, str_replace( $translateable_string, $translated_strings[$i], $nodes[$i]['node']->getAttribute( $accessor ) ) );
451
  }else{
452
  if ( strpos ( $nodes[$i]['node']->$accessor, $translateable_string ) === false ){
453
  $translateable_string = $alternate_translateable_string;
@@ -507,6 +514,12 @@ class TRP_Translation_Render{
507
  $a_href->href = str_replace('#TRPLINKPROCESSED', '', $a_href->href);
508
  }
509
 
 
 
 
 
 
 
510
 
511
  return $html->save();
512
  }
@@ -751,6 +764,26 @@ class TRP_Translation_Render{
751
  return $location;
752
  }
753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
  /**
755
  * Filters the output buffer of ajax calls that return json and adds the preview arg to urls
756
  * @param $output
@@ -781,4 +814,41 @@ class TRP_Translation_Render{
781
  $item = add_query_arg( 'trp-edit-translation', 'preview', $item );
782
  }
783
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
784
  }
57
  }
58
 
59
  /**
60
+ * Forces the language to be the first non default one in the preview translation editor.
61
+ * We're doing this because we need the ID's.
62
+ * Otherwise we're just returning the global $TRP_LANGUAGE
63
  *
64
  * @return string Language code.
65
  */
66
+ protected function force_language_in_preview(){
67
  global $TRP_LANGUAGE;
68
  if ( in_array( $TRP_LANGUAGE, $this->settings['translation-languages'] ) ) {
69
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ){
70
+ // in the translation editor we need a different language then the default because we need string ID's.
71
+ // so we're forcing it to the first translation language because if it's the default, we're just returning the $output
72
  if ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) {
73
  if( count( $this->settings['publish-languages'] ) > 1 ){
74
  foreach ($this->settings['translation-languages'] as $language) {
96
  * @return string Trimmed string.
97
  */
98
  public function full_trim( $word ) {
99
+ /* apparently the � char in the trim function turns some strings in an empty string so they can't be translated but I don't really know if we should remove it completely */
100
+ //$word = trim($word," \t\n\r\0\x0B\xA0�".chr( 194 ) . chr( 160 ) );
101
+ $word = trim($word," \t\n\r\0\x0B\xA0".chr( 194 ) . chr( 160 ) );
102
  if ( htmlentities( $word ) == "" || strip_tags( $word ) == "" || trim ($word, " \t\n\r\0\x0B\xA0�.,/`~!@#\$€£%^&*():;-_=+[]{}\\|?/<>1234567890'\"" ) == '' ){
103
  $word = '';
104
  }
212
  * @return string Translated HTML page.
213
  */
214
  public function translate_page( $output ){
215
+ $output = apply_filters('trp_before_translate_content', $output);
216
+
217
  if ( strlen( $output ) < 1 ){
218
  return $output;
219
  }
220
+
221
  global $TRP_LANGUAGE;
222
+ $language_code = $this->force_language_in_preview();
223
  if ($language_code === false) {
224
  return $output;
225
  }
233
  return $output;
234
  }
235
 
 
 
236
  //check if we have a json response
237
  if (is_array($json_array = json_decode($output, true))) {
238
  if (!empty($json_array)) {
414
  ),
415
  'meta_desc' => array(
416
  'accessor' => 'content',
417
+ 'attribute' => true
418
  ),
419
  'post_slug' => array(
420
  'accessor' => 'content',
454
  if ( strpos ( $nodes[$i]['node']->getAttribute( $accessor ), $translateable_string ) === false ){
455
  $translateable_string = $alternate_translateable_string;
456
  }
457
+ $nodes[$i]['node']->setAttribute( $accessor, str_replace( $translateable_string, esc_attr( $translated_strings[$i] ), $nodes[$i]['node']->getAttribute( $accessor ) ) );
458
  }else{
459
  if ( strpos ( $nodes[$i]['node']->$accessor, $translateable_string ) === false ){
460
  $translateable_string = $alternate_translateable_string;
514
  $a_href->href = str_replace('#TRPLINKPROCESSED', '', $a_href->href);
515
  }
516
 
517
+ // pass the current language in forms where the action does not contain the language
518
+ // based on this we're filtering wp_redirect to include the proper URL when returing to the current page.
519
+ foreach ( $html->find('form') as $k => $row ){
520
+ $row->innertext .= '<input type="hidden" name="trp-form-language" value="'. $TRP_LANGUAGE .'"/>';
521
+ }
522
+
523
 
524
  return $html->save();
525
  }
764
  return $location;
765
  }
766
 
767
+ /**
768
+ * Filters the location redirect to add the current language based on the trp-form-language parameter
769
+ * @param $location
770
+ * @param $status
771
+ * @return string
772
+ * @since 1.1.2
773
+ */
774
+ public function force_language_on_form_url_redirect( $location, $status ){
775
+ if( isset( $_REQUEST['trp-form-language'] ) && !empty($_REQUEST['trp-form-language']) ){
776
+ $form_language = esc_attr($_REQUEST['trp-form-language']);
777
+ if ( ! $this->url_converter ) {
778
+ $trp = TRP_Translate_Press::get_trp_instance();
779
+ $this->url_converter = $trp->get_component('url_converter');
780
+ }
781
+
782
+ $location = $this->url_converter->get_url_for_language( $form_language, $location );
783
+ }
784
+ return $location;
785
+ }
786
+
787
  /**
788
  * Filters the output buffer of ajax calls that return json and adds the preview arg to urls
789
  * @param $output
814
  $item = add_query_arg( 'trp-edit-translation', 'preview', $item );
815
  }
816
  }
817
+
818
+ /**
819
+ * Filters the output buffer of ajax calls that return json and adds the preview arg to urls
820
+ * @param $output
821
+ * @return string
822
+ * @since 1.1.2
823
+ */
824
+ public function force_form_language_on_url_in_ajax( $output ){
825
+ if ( TRP_Translation_Manager::is_ajax_on_frontend() && isset( $_REQUEST['trp-form-language'] ) && !empty( $_REQUEST['trp-form-language'] ) ) {
826
+ $result = json_decode($output, TRUE);
827
+ if ( json_last_error() === JSON_ERROR_NONE) {
828
+ array_walk_recursive($result, array($this, 'callback_add_language_to_url'));
829
+ $output = trp_safe_json_encode($result);
830
+ } //endif
831
+ } //endif
832
+ return $output;
833
+ }
834
+
835
+ /**
836
+ * Adds preview query arg to links that are url's. callback specifically for the array_walk_recursive function
837
+ * @param $item
838
+ * @param $key
839
+ * @return string
840
+ * @internal param $output
841
+ * @since 1.1.2
842
+ */
843
+ function callback_add_language_to_url(&$item, $key){
844
+ if ( filter_var($item, FILTER_VALIDATE_URL) !== FALSE ) {
845
+ $form_language = esc_attr($_REQUEST['trp-form-language']);
846
+ if ( ! $this->url_converter ) {
847
+ $trp = TRP_Translate_Press::get_trp_instance();
848
+ $this->url_converter = $trp->get_component('url_converter');
849
+ }
850
+
851
+ $item = $this->url_converter->get_url_for_language( $form_language, $item );
852
+ }
853
+ }
854
  }
includes/class-url-converter.php CHANGED
@@ -126,13 +126,8 @@ class TRP_Url_Converter {
126
  $language = $TRP_LANGUAGE;
127
  }
128
 
129
-
130
- if ( empty( $url ) ) {
131
- $url = $this->cur_page_url();
132
- }
133
-
134
  // if we have the homepage, we replace it with the filtered homepage that contains the language url.
135
- if( trailingslashit($url)== trailingslashit($this->get_abs_home()) ){
136
  $TRP_LANGUAGE = $language;
137
  $new_url = home_url();
138
  $TRP_LANGUAGE = $trp_language_copy;
@@ -146,6 +141,9 @@ class TRP_Url_Converter {
146
  $new_url = get_permalink( $post->ID );
147
  $TRP_LANGUAGE = $trp_language_copy;
148
  }else{
 
 
 
149
  // If no $post is set we simply replace the current language root with the new language root.
150
  // we can't assume the URL's have / at the end so we need to untrailingslashit both $abs_home and $new_language_root
151
  $abs_home = trailingslashit( $this->get_abs_home() );
@@ -282,9 +280,8 @@ class TRP_Url_Converter {
282
  $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
283
 
284
  // Trim path info from the end and the leading home path from the front.
285
- $req_uri = trim($req_uri, '/');
286
  $req_uri = preg_replace( $home_path_regex, '', $req_uri );
287
- $req_uri = trim($req_uri, '/');
288
  $req_uri = trim($this->get_abs_home(), '/') . '/' . ltrim( $req_uri, '/' );
289
 
290
 
126
  $language = $TRP_LANGUAGE;
127
  }
128
 
 
 
 
 
 
129
  // if we have the homepage, we replace it with the filtered homepage that contains the language url.
130
+ if( trailingslashit( $this->cur_page_url() ) == trailingslashit($this->get_abs_home()) ){
131
  $TRP_LANGUAGE = $language;
132
  $new_url = home_url();
133
  $TRP_LANGUAGE = $trp_language_copy;
141
  $new_url = get_permalink( $post->ID );
142
  $TRP_LANGUAGE = $trp_language_copy;
143
  }else{
144
+ if( empty( $url ) ){
145
+ $url = $this->cur_page_url();
146
+ }
147
  // If no $post is set we simply replace the current language root with the new language root.
148
  // we can't assume the URL's have / at the end so we need to untrailingslashit both $abs_home and $new_language_root
149
  $abs_home = trailingslashit( $this->get_abs_home() );
280
  $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
281
 
282
  // Trim path info from the end and the leading home path from the front.
283
+ $req_uri = ltrim($req_uri, '/');
284
  $req_uri = preg_replace( $home_path_regex, '', $req_uri );
 
285
  $req_uri = trim($this->get_abs_home(), '/') . '/' . ltrim( $req_uri, '/' );
286
 
287
 
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site, with full support for WooCommerce and site builders.
6
- Version: 1.1.1
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  License: GPL2
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site, with full support for WooCommerce and site builders.
6
+ Version: 1.1.2
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  License: GPL2
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.cozmoslabs.com/
4
  Tags: translate, translation, multilingual, automatic translation, front-end translation, google translate, bilingual
5
  Requires at least: 3.1.0
6
  Tested up to: 4.9.1
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,6 +107,14 @@ For more information please check out [TranslatePress documentation](https://tra
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
 
 
110
  = 1.1.1 =
111
  * Fixed js error with startsWith method not being supported in IE
112
  * Removed unnecessary files from select2 lib
4
  Tags: translate, translation, multilingual, automatic translation, front-end translation, google translate, bilingual
5
  Requires at least: 3.1.0
6
  Tested up to: 4.9.1
7
+ Stable tag: 1.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = 1.1.2 =
111
+ We now make sure that all forms when submitted redirect to the correct language
112
+ Fixed an issue with missing slash from language switcher
113
+ Fixed an issue where we were not redirecting to the correct url slug when switching languages
114
+ Fixed a possible notice inside the get_language_names function
115
+ Fixed html breaking because of unescaped quotes in translated meta content
116
+ Removed a special character from the full_trim function that was causing some strings to not be selectable for translation
117
+
118
  = 1.1.1 =
119
  * Fixed js error with startsWith method not being supported in IE
120
  * Removed unnecessary files from select2 lib