TranslatePress – Translate Multilingual sites - Version 1.0.2

Version Description

  • Translation interface improvements
  • Fixed issues with strings loaded with ajax
  • Added an addon page
  • Fixed bug with gettext node accidentally wrapping another string too.
Download this release

Release Info

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

Code changes from version 1.0.1 to 1.0.2

assets/css/trp-editor-style.css CHANGED
@@ -6,14 +6,14 @@ body{
6
  }
7
 
8
  #trp-editor{
9
- margin-left: 300px;
10
  position: fixed;
11
  width: 100%;
12
  height: 100%;
13
  }
14
 
15
  #trp-controls{
16
- width: 298px;
17
  position: fixed;
18
  top: 0;
19
  bottom: 0;
@@ -77,7 +77,6 @@ body{
77
  cursor: pointer;
78
  font: 400 26px/40px dashicons;
79
  font-weight: bold;
80
- content: "\f335";
81
  display: inline-block;
82
  width: 45px;
83
  height: 41px;
@@ -95,6 +94,10 @@ body{
95
  text-decoration: none;
96
  }
97
 
 
 
 
 
98
  #trp-controls-close:focus,
99
  #trp-controls-close:hover{
100
  background: #fff;
@@ -108,7 +111,7 @@ body{
108
  #trp-preview{
109
  position: absolute;
110
  left: 0;
111
- right: 300px;
112
  height: 100%;
113
  }
114
 
@@ -192,12 +195,15 @@ span.select2-container{
192
  }
193
 
194
  .trp-language-text textarea{
195
- height: 65px;
196
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
197
  font-size: 14px;
198
  max-width: 100%;
199
  min-width: 100%;
200
  width: 100%;
 
 
 
201
  }
202
 
203
  .trp-language-text textarea[readonly="readonly"]{
@@ -401,3 +407,51 @@ spin {
401
  transform: rotate(360deg)
402
  }
403
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  }
7
 
8
  #trp-editor{
9
+ margin-left: 350px;
10
  position: fixed;
11
  width: 100%;
12
  height: 100%;
13
  }
14
 
15
  #trp-controls{
16
+ width: 348px;
17
  position: fixed;
18
  top: 0;
19
  bottom: 0;
77
  cursor: pointer;
78
  font: 400 26px/40px dashicons;
79
  font-weight: bold;
 
80
  display: inline-block;
81
  width: 45px;
82
  height: 41px;
94
  text-decoration: none;
95
  }
96
 
97
+ #trp-controls-close:after{
98
+ content: "\f335";
99
+ }
100
+
101
  #trp-controls-close:focus,
102
  #trp-controls-close:hover{
103
  background: #fff;
111
  #trp-preview{
112
  position: absolute;
113
  left: 0;
114
+ right: 350px;
115
  height: 100%;
116
  }
117
 
195
  }
196
 
197
  .trp-language-text textarea{
198
+ height: 80px;
199
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
200
  font-size: 14px;
201
  max-width: 100%;
202
  min-width: 100%;
203
  width: 100%;
204
+ padding: 3px;
205
+ border: 1px solid #aaa;
206
+ border-radius:3px;
207
  }
208
 
209
  .trp-language-text textarea[readonly="readonly"]{
407
  transform: rotate(360deg)
408
  }
409
  }
410
+
411
+ #trp-preview.trp-still-loading-strings:before{
412
+ position: absolute; /* Sit on top of the page content */
413
+ width: 100%; /* Full width (cover the whole page) */
414
+ height: 30px; /* Full height (cover the whole page) */
415
+ line-height:30px;
416
+ top: 0;
417
+ left: 0;
418
+ right: 0;
419
+ background-color: rgba(40,177,255,0.8); /* Black background with opacity */
420
+ z-index: 200; /* Specify a stack order in case you're using a different order for other elements */
421
+ cursor: pointer; /* Add a pointer on hover */
422
+ content:'The strings are not yet ready for translation. Try again in a moment...';
423
+ color:#fff;
424
+ text-align:center;
425
+ }
426
+ /*
427
+ * Select 2 Overlay in front-end
428
+ */
429
+
430
+ .select2-selection.select2-selection--single{
431
+ outline: 0;
432
+ }
433
+
434
+ #trp_select2_overlay{
435
+ display: none;
436
+ position: absolute;
437
+ top: 0;
438
+ left: 0;
439
+ width: 100%;
440
+ height: 100%;
441
+ background-color: #000;
442
+ filter:alpha(opacity=50);
443
+ -moz-opacity:0.5;
444
+ -khtml-opacity: 0.5;
445
+ opacity: 0.5;
446
+ z-index: 1000;
447
+ }
448
+
449
+ .select2-container{
450
+ z-index: 1051;
451
+ }
452
+
453
+ .select2-container--default .select2-results > .select2-results__options,
454
+ .select2-container--default .select2-results > .select2-results__options,
455
+ .select2-results{
456
+ max-height: 400px !important;
457
+ }
assets/images/multiple_lang_icon.png ADDED
Binary file
assets/images/seo_icon_translatepress.png ADDED
Binary file
assets/js/trp-editor-overlay.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready(function(){
2
+ /* jQuery('#wppb_manage_fields #field').select2({
3
+ placeholder: 'Select an option'
4
+ })*/
5
+
6
+ var overlay = jQuery('<div id="trp_select2_overlay"> </div>')
7
+ overlay.appendTo('#trp-controls');
8
+
9
+ var $eventSelectLanguage = jQuery("#trp-language-select");
10
+ $eventSelectLanguage.on("select2:open", function (e) {
11
+ jQuery('#trp_select2_overlay').fadeIn('100')
12
+ });
13
+ $eventSelectLanguage.on("select2:close", function (e) {
14
+ jQuery('#trp_select2_overlay').hide();
15
+ });
16
+
17
+ var $eventSelectString = jQuery("#trp-string-categories");
18
+ $eventSelectString.on("select2:open", function (e) {
19
+ jQuery('#trp_select2_overlay').fadeIn('100')
20
+ });
21
+ $eventSelectString.on("select2:close", function (e) {
22
+ jQuery('#trp_select2_overlay').hide();
23
+ });
24
+
25
+
26
+
27
+ })
assets/js/trp-editor-script.js CHANGED
@@ -164,7 +164,7 @@ function TRP_Editor(){
164
  }
165
  }
166
  }
167
- _this.saved_translation_ui();
168
  };
169
 
170
  /**
@@ -286,14 +286,17 @@ function TRP_Editor(){
286
  /**
287
  * Show UI for translation done saving.
288
  */
289
- this.saved_translation_ui = function(){
 
290
  save_button.removeAttr( 'disabled' );
291
  if( gettext_dictionaries != null )
292
  loading_animation.css('display', 'none');//don't hide the animation if the gettexts arent loaded
293
  if ( _this.change_tracker ) {
294
  _this.change_tracker.mark_changes_saved();
295
- translation_saved.css("display","inline");
296
- translation_saved.delay(3000).fadeOut(400);
 
 
297
  }
298
  };
299
 
@@ -680,7 +683,18 @@ function TRP_String( language, array_index ){
680
  if ( trpEditor.change_tracker.check_unsaved_changes() ) {
681
  return;
682
  }
683
- trpEditor.jquery_string_selector.val( _this.index ).trigger( 'change', true )
 
 
 
 
 
 
 
 
 
 
 
684
  });
685
 
686
  jQuery( this ).addClass( 'trp-highlight' );
@@ -859,7 +873,17 @@ function TRP_Lister( current_dictionary ) {
859
  return;
860
  }
861
  string_id = jquery_object.attr('data-trpgettextoriginal');
862
- trpEditor.jquery_string_selector.val('gettext-'+string_id).trigger( 'change', true );
 
 
 
 
 
 
 
 
 
 
863
  }
864
 
865
  }
@@ -1164,4 +1188,15 @@ jQuery(function(){
1164
 
1165
  });
1166
 
 
 
 
 
 
 
 
 
 
 
 
1167
 
164
  }
165
  }
166
  }
167
+ _this.saved_translation_ui(true);
168
  };
169
 
170
  /**
286
  /**
287
  * Show UI for translation done saving.
288
  */
289
+ this.saved_translation_ui = function( dontShowMessage ){
290
+ dontShowMessage = dontShowMessage || 0;
291
  save_button.removeAttr( 'disabled' );
292
  if( gettext_dictionaries != null )
293
  loading_animation.css('display', 'none');//don't hide the animation if the gettexts arent loaded
294
  if ( _this.change_tracker ) {
295
  _this.change_tracker.mark_changes_saved();
296
+ if( !dontShowMessage ) {
297
+ translation_saved.css("display", "inline");
298
+ translation_saved.delay(3000).fadeOut(400);
299
+ }
300
  }
301
  };
302
 
683
  if ( trpEditor.change_tracker.check_unsaved_changes() ) {
684
  return;
685
  }
686
+
687
+ notDoingAjax = true;
688
+ if( typeof jQuery.active != 'undefined' ){
689
+ if( jQuery.active !== 0 )
690
+ notDoingAjax = false;
691
+ }
692
+
693
+ if( jQuery( 'option[value="'+_this.index+'"]', trpEditor.jquery_string_selector ).length != 0 && !jQuery('.trp-ajax-loader', trpEditor).is(":visible") && notDoingAjax ) {
694
+ trpEditor.jquery_string_selector.val( _this.index ).trigger( 'change', true )
695
+ }else{
696
+ trpEditor.jquery_string_selector.trigger('trpSelectorNotChanged');
697
+ }
698
  });
699
 
700
  jQuery( this ).addClass( 'trp-highlight' );
873
  return;
874
  }
875
  string_id = jquery_object.attr('data-trpgettextoriginal');
876
+
877
+ notDoingAjax = true;
878
+ if( typeof jQuery.active != 'undefined' ){
879
+ if( jQuery.active !== 0 )
880
+ notDoingAjax = false;
881
+ }
882
+ if( jQuery( 'option[value="gettext-'+string_id+'"]', trpEditor.jquery_string_selector ).length != 0 && !jQuery('.trp-ajax-loader', trpEditor).is(":visible") && notDoingAjax ) {
883
+ trpEditor.jquery_string_selector.val('gettext-' + string_id).trigger('change', true);
884
+ }else{
885
+ trpEditor.jquery_string_selector.trigger('trpSelectorNotChanged');
886
+ }
887
  }
888
 
889
  }
1188
 
1189
  });
1190
 
1191
+ jQuery( function(){
1192
+ trpEditor.jquery_string_selector.on('trpSelectorNotChanged', function(){
1193
+ if( !jQuery('#trp-preview').hasClass('trp-still-loading-strings') ) {
1194
+ jQuery('#trp-preview').addClass('trp-still-loading-strings');
1195
+ setTimeout(function () {
1196
+ jQuery('#trp-preview').removeClass('trp-still-loading-strings')
1197
+ }, 2000 );
1198
+ }
1199
+ });
1200
+ });
1201
+
1202
 
assets/js/trp-translate-dom-changes.js CHANGED
@@ -32,6 +32,7 @@ function TRP_Translator(){
32
  _this.ajax_get_translation( strings_to_query, wp_ajax_url );
33
  }else{
34
  _this.update_strings( response, strings_to_query );
 
35
  }
36
  },
37
  error: function( errorThrown ){
@@ -58,6 +59,10 @@ function TRP_Translator(){
58
  var response_string = response[language_to_query][i];
59
  if (response_string.original.trim() == queried_string.original.trim()) {
60
  response[language_to_query][i].jquery_object = jQuery( queried_string.node ).parent( 'translate-press' );
 
 
 
 
61
  if (response_string.translated != '' && language_to_query == current_language ) {
62
  var text_to_set = initial_value.replace(initial_value.trim(), response_string.translated);
63
  _this.pause_observer();
@@ -93,8 +98,18 @@ function TRP_Translator(){
93
  for (var i = 0; i < mutation.addedNodes.length; i++) {
94
  if ( mutation.addedNodes[i].innerText && _this.trim( mutation.addedNodes[i].innerText.trim(), except_characters ) != '' ) {
95
  var node = jQuery( mutation.addedNodes[i] );
96
- var attribute = node.attr( 'data-no-translation' );
97
- if ( (typeof attribute !== typeof undefined && attribute !== false) || node.parents( '[data-no-translation]').length > 0 ){
 
 
 
 
 
 
 
 
 
 
98
  continue;
99
  }
100
 
@@ -106,7 +121,9 @@ function TRP_Translator(){
106
  var all_nodes = jQuery( mutation.addedNodes[i]).find( '*').addBack();
107
  var all_strings = all_nodes.contents().filter(function(){
108
  if( this.nodeType === 3 && /\S/.test(this.nodeValue) ){
109
- return this
 
 
110
  }
111
  });
112
  if ( typeof parent.trpEditor !== 'undefined' ) {
@@ -178,9 +195,9 @@ function TRP_Translator(){
178
  current_language = trp_data.trp_current_language;
179
  original_language = trp_data.trp_original_language;
180
  language_to_query = trp_data.trp_language_to_query;
 
181
  // create an observer instance
182
  observer = new MutationObserver( _this.detect_new_strings );
183
-
184
  // configuration of the observer:
185
  var config = {
186
  attributes: true,
@@ -189,8 +206,17 @@ function TRP_Translator(){
189
  subtree: true
190
  };
191
 
 
192
  observer.observe( document.body , config );
193
 
 
 
 
 
 
 
 
 
194
  //try a final attempt at cleaning the gettext wrappers
195
  _this.cleanup_gettext_wrapper();
196
  };
32
  _this.ajax_get_translation( strings_to_query, wp_ajax_url );
33
  }else{
34
  _this.update_strings( response, strings_to_query );
35
+ //window.parent.jQuery('#trp-preview-iframe').trigger('load');
36
  }
37
  },
38
  error: function( errorThrown ){
59
  var response_string = response[language_to_query][i];
60
  if (response_string.original.trim() == queried_string.original.trim()) {
61
  response[language_to_query][i].jquery_object = jQuery( queried_string.node ).parent( 'translate-press' );
62
+ if ( typeof parent.trpEditor !== 'undefined' ) {
63
+ response[language_to_query][i].jquery_object.attr('data-trp-translate-id', response[language_to_query][i].id);
64
+ response[language_to_query][i].jquery_object.attr('data-trp-node-type', 'Dynamic Added Strings');
65
+ }
66
  if (response_string.translated != '' && language_to_query == current_language ) {
67
  var text_to_set = initial_value.replace(initial_value.trim(), response_string.translated);
68
  _this.pause_observer();
98
  for (var i = 0; i < mutation.addedNodes.length; i++) {
99
  if ( mutation.addedNodes[i].innerText && _this.trim( mutation.addedNodes[i].innerText.trim(), except_characters ) != '' ) {
100
  var node = jQuery( mutation.addedNodes[i] );
101
+ var noTranslation = node.attr( 'data-no-translation' );
102
+ if ( (typeof noTranslation !== typeof undefined && noTranslation !== false) || node.parents( '[data-no-translation]').length > 0 ){
103
+ continue;
104
+ }
105
+
106
+ var gettextString = node.attr( 'data-trpgettextoriginal' );
107
+ if ( (typeof gettextString !== typeof undefined && gettextString !== false) || node.parents( '[data-trpgettextoriginal]').length > 0 ){
108
+ continue;
109
+ }
110
+
111
+ var simpleString = node.attr( 'data-trp-translate-id' );
112
+ if ( (typeof simpleString !== typeof undefined && simpleString !== false) || node.parents( '[data-trp-translate-id]').length > 0 ){
113
  continue;
114
  }
115
 
121
  var all_nodes = jQuery( mutation.addedNodes[i]).find( '*').addBack();
122
  var all_strings = all_nodes.contents().filter(function(){
123
  if( this.nodeType === 3 && /\S/.test(this.nodeValue) ){
124
+ if ( jQuery(this).parents( '[data-trpgettextoriginal]').length == 0 && jQuery(this).parents( '[data-trp-translate-id]').length == 0 ){
125
+ return this;
126
+ }
127
  }
128
  });
129
  if ( typeof parent.trpEditor !== 'undefined' ) {
195
  current_language = trp_data.trp_current_language;
196
  original_language = trp_data.trp_original_language;
197
  language_to_query = trp_data.trp_language_to_query;
198
+
199
  // create an observer instance
200
  observer = new MutationObserver( _this.detect_new_strings );
 
201
  // configuration of the observer:
202
  var config = {
203
  attributes: true,
206
  subtree: true
207
  };
208
 
209
+
210
  observer.observe( document.body , config );
211
 
212
+ jQuery( document ).ajaxComplete(function( event, request, settings ) {
213
+ if( window.parent.jQuery('#trp-preview-iframe').length != 0 ) {
214
+ if( typeof settings.data == 'undefined' || settings.data.indexOf('action=trp_') === -1 ) {
215
+ window.parent.jQuery('#trp-preview-iframe').trigger('load');
216
+ }
217
+ }
218
+ });
219
+
220
  //try a final attempt at cleaning the gettext wrappers
221
  _this.cleanup_gettext_wrapper();
222
  };
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' );
42
- define( 'TRP_PLUGIN_VERSION', '1.0.1' );
43
 
44
  $this->load_dependencies();
45
  $this->initialize_components();
@@ -110,6 +110,8 @@ class TRP_Translate_Press{
110
 
111
  $this->loader->add_action( 'wp_ajax_trp_get_translations', $this->translation_manager, 'get_translations' );
112
  $this->loader->add_action( 'wp_ajax_trp_save_translations', $this->translation_manager, 'save_translations' );
 
 
113
 
114
  $this->loader->add_action( 'wp_ajax_trp_gettext_get_translations', $this->translation_manager, 'gettext_get_translations' );
115
  $this->loader->add_action( 'wp_ajax_trp_gettext_save_translations', $this->translation_manager, 'gettext_save_translations' );
@@ -123,6 +125,7 @@ class TRP_Translate_Press{
123
  */
124
  protected function define_frontend_hooks(){
125
  $this->loader->add_action( 'wp', $this->translation_render, 'start_output_buffer' );
 
126
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
127
 
128
 
@@ -153,8 +156,10 @@ class TRP_Translate_Press{
153
  /* handle dynamic texts with gettext */
154
  $this->loader->add_filter( 'locale', $this->languages, 'change_locale' );
155
 
156
- $this->loader->add_action( 'init', $this->translation_manager, 'create_gettext_translated_global', 11 );
157
- $this->loader->add_action( 'wp_head', $this->translation_manager, 'apply_gettext_filter', 100 );
 
 
158
  $this->loader->add_action( 'shutdown', $this->translation_manager, 'machine_translate_gettext', 100 );
159
 
160
  /* we need the esc_ functions for html and attributes not to escape our tags so we put them back */
39
  define( 'TRP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
40
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41
  define( 'TRP_PLUGIN_SLUG', 'translatepress' );
42
+ define( 'TRP_PLUGIN_VERSION', '1.0.2' );
43
 
44
  $this->load_dependencies();
45
  $this->initialize_components();
110
 
111
  $this->loader->add_action( 'wp_ajax_trp_get_translations', $this->translation_manager, 'get_translations' );
112
  $this->loader->add_action( 'wp_ajax_trp_save_translations', $this->translation_manager, 'save_translations' );
113
+
114
+ $this->loader->add_action( 'wp_ajax_trp_process_js_strings_in_translation_editor', $this->translation_render, 'process_js_strings_in_translation_editor' );
115
 
116
  $this->loader->add_action( 'wp_ajax_trp_gettext_get_translations', $this->translation_manager, 'gettext_get_translations' );
117
  $this->loader->add_action( 'wp_ajax_trp_gettext_save_translations', $this->translation_manager, 'gettext_save_translations' );
125
  */
126
  protected function define_frontend_hooks(){
127
  $this->loader->add_action( 'wp', $this->translation_render, 'start_output_buffer' );
128
+ $this->loader->add_action( 'admin_init', $this->translation_render, 'start_output_buffer' );
129
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
130
 
131
 
156
  /* handle dynamic texts with gettext */
157
  $this->loader->add_filter( 'locale', $this->languages, 'change_locale' );
158
 
159
+ $this->loader->add_action( 'init', $this->translation_manager, 'create_gettext_translated_global' );
160
+ $this->loader->add_action( 'admin_init', $this->translation_manager, 'create_gettext_translated_global' );
161
+ $this->loader->add_action( 'init', $this->translation_manager, 'apply_gettext_filter_on_frontend' );
162
+ $this->loader->add_action( 'admin_init', $this->translation_manager, 'apply_gettext_filter' );
163
  $this->loader->add_action( 'shutdown', $this->translation_manager, 'machine_translate_gettext', 100 );
164
 
165
  /* we need the esc_ functions for html and attributes not to escape our tags so we put them back */
includes/class-settings.php CHANGED
@@ -66,6 +66,7 @@ class TRP_Settings{
66
  */
67
  public function register_menu_page(){
68
  add_options_page( 'TranslatePress', 'TranslatePress', apply_filters( 'trp_settings_capability', 'manage_options' ), 'translate-press', array( $this, 'settings_page_content' ) );
 
69
  }
70
 
71
  /**
@@ -80,6 +81,13 @@ class TRP_Settings{
80
  require_once TRP_PLUGIN_DIR . 'partials/main-settings-page.php';
81
  }
82
 
 
 
 
 
 
 
 
83
  /**
84
  * Register settings option.
85
  */
@@ -435,6 +443,13 @@ class TRP_Settings{
435
  'page' => 'trp_license_key'
436
  );
437
  }
 
 
 
 
 
 
 
438
 
439
  $active_tab = 'translate-press';
440
  if ( isset( $_GET['page'] ) ){
66
  */
67
  public function register_menu_page(){
68
  add_options_page( 'TranslatePress', 'TranslatePress', apply_filters( 'trp_settings_capability', 'manage_options' ), 'translate-press', array( $this, 'settings_page_content' ) );
69
+ add_submenu_page( 'TRPHidden', 'TranslatePress Addons', 'TRPHidden', 'manage_options', 'trp_addons_page', array($this, 'addons_page_content') );
70
  }
71
 
72
  /**
81
  require_once TRP_PLUGIN_DIR . 'partials/main-settings-page.php';
82
  }
83
 
84
+ /**
85
+ * Addons page content.
86
+ */
87
+ public function addons_page_content(){
88
+ require_once TRP_PLUGIN_DIR . 'partials/addons-settings-page.php';
89
+ }
90
+
91
  /**
92
  * Register settings option.
93
  */
443
  'page' => 'trp_license_key'
444
  );
445
  }
446
+ else{
447
+ $tabs[] = array(
448
+ 'name' => __( 'Addons', TRP_PLUGIN_SLUG ),
449
+ 'url' => admin_url( 'admin.php?page=trp_addons_page' ),
450
+ 'page' => 'trp_addons_page'
451
+ );
452
+ }
453
 
454
  $active_tab = 'translate-press';
455
  if ( isset( $_GET['page'] ) ){
includes/class-translation-manager.php CHANGED
@@ -30,7 +30,7 @@ class TRP_Translation_Manager{
30
  * @return bool Whether current page is part of the Translation Editor.
31
  */
32
  protected function conditions_met( $mode = 'true' ){
33
- if ( isset( $_GET['trp-edit-translation'] ) && esc_attr( $_GET['trp-edit-translation'] ) == $mode ) {
34
  if ( current_user_can( 'manage_options' ) && ! is_admin() ) {
35
  return true;
36
  }else{
@@ -70,8 +70,10 @@ class TRP_Translation_Manager{
70
  wp_enqueue_script( 'trp-translation-manager-script', TRP_PLUGIN_URL . 'assets/js/trp-editor-script.js', array(), TRP_PLUGIN_VERSION );
71
  wp_enqueue_style( 'trp-translation-manager-style', TRP_PLUGIN_URL . 'assets/css/trp-editor-style.css', array(), TRP_PLUGIN_VERSION );
72
 
73
- $scripts_to_print = apply_filters( 'trp-scripts-for-editor', array( 'jquery', 'jquery-ui-core', 'jquery-effects-core', 'jquery-ui-resizable', 'trp-translation-manager-script', 'trp-select2-lib-js' ) );
74
- $styles_to_print = apply_filters( 'trp-styles-for-editor', array( 'trp-translation-manager-style', 'trp-select2-lib-css' /*'wp-admin', 'dashicons', 'common', 'site-icon', 'buttons'*/ ) );
 
 
75
  wp_print_scripts( $scripts_to_print );
76
  wp_print_styles( $styles_to_print );
77
  }
@@ -280,7 +282,8 @@ class TRP_Translation_Manager{
280
  if( !empty( $lang_original_string_details ) ){
281
  foreach( $lang_original_string_details as $lang_original_string_detail ){
282
 
283
- $translated = translate( $lang_original_string_detail['original'], $lang_original_string_detail['domain'] );
 
284
 
285
  $db_id = $this->trp_query->insert_gettext_strings( array( array('original' => $lang_original_string_detail['original'], 'translated' => $translated, 'domain' => $lang_original_string_detail['domain']) ), $language );
286
  $dictionaries[$language][] = array('id' => $db_id, 'original' => $lang_original_string_detail['original'], 'translated' => ( $translated != $lang_original_string_detail['original'] ) ? $translated : '', 'domain' => $lang_original_string_detail['domain']);
@@ -466,7 +469,7 @@ class TRP_Translation_Manager{
466
  * Create a global with the gettext strings that exist in the database
467
  */
468
  public function create_gettext_translated_global(){
469
- if( !is_admin() ) {
470
  global $TRP_LANGUAGE;
471
 
472
  global $trp_translated_gettext_texts;
@@ -481,9 +484,22 @@ class TRP_Translation_Manager{
481
  }
482
  }
483
 
484
- /* only apply the gettext filter from the wp_head hook down */
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  public function apply_gettext_filter(){
486
- if( !is_admin() ) {
487
  add_filter('gettext', array($this, 'process_gettext_strings'), 100, 3);
488
  add_filter('gettext_with_context', array($this, 'process_gettext_strings_with_context'), 100, 4);
489
  add_filter('ngettext', array($this, 'process_ngettext_strings'), 100, 5);
@@ -491,6 +507,55 @@ class TRP_Translation_Manager{
491
  }
492
  }
493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
 
495
  /**
496
  * Function that replaces the translations with the ones in the database if they are differnt, wrapps the texts in the html and
@@ -507,27 +572,15 @@ class TRP_Translation_Manager{
507
  if( count( $this->settings['publish-languages'] ) <= 1 )
508
  return $translation;
509
 
510
- if( ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'true' ) || $domain == TRP_PLUGIN_SLUG )
511
  return $translation;
512
 
 
 
 
513
 
514
- if ( !defined( 'DOING_AJAX' ) ) {
515
- $callstack_functions = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
516
- if( !empty( $callstack_functions ) ){
517
- foreach( $callstack_functions as $callstack_function ){
518
- if( $callstack_function['function'] == 'wp_enqueue_script' ||
519
- $callstack_function['function'] == 'wp_enqueue_scripts' ||
520
- $callstack_function['function'] == 'wp_editor' ||
521
- $callstack_function['function'] == 'wp_enqueue_media' ||
522
- $callstack_function['function'] == 'wp_register_script' ||
523
- $callstack_function['function'] == 'wp_print_scripts'||
524
- $callstack_function['function'] == 'wp_localize_script'||
525
- $callstack_function['function'] == 'wp_print_media_templates'
526
- ) {
527
- return $translation;
528
- }
529
- }
530
- }
531
 
532
  global $trp_translated_gettext_texts, $trp_all_gettext_texts;
533
  $found_in_db = false;
@@ -552,7 +605,7 @@ class TRP_Translation_Manager{
552
  $found_in_db = true;
553
  /* update the db if a translation appeared in the po file later */
554
  if( empty( $trp_translated_gettext_text['translated'] ) && $translation != $text ) {
555
- $this->trp_query->update_gettext_strings( array( array( 'id' => $db_id, 'original' => $text, 'translated' => $translation, 'domain' => $domain), 'status' => TRP_Query::HUMAN_REVIEWED ), $TRP_LANGUAGE );
556
  }
557
 
558
  break;
@@ -563,7 +616,7 @@ class TRP_Translation_Manager{
563
  if( !$found_in_db ){
564
  if( !in_array( array('original' => $text, 'translated' => $translation, 'domain' => $domain), $trp_all_gettext_texts ) ) {
565
  $trp_all_gettext_texts[] = array('original' => $text, 'translated' => $translation, 'domain' => $domain);
566
- $db_id = $this->trp_query->insert_gettext_strings( array( array('original' => $text, 'translated' => $translation, 'domain' => $domain) ), $TRP_LANGUAGE );
567
  /* insert it in the global of translated because now it is in the database */
568
  $trp_translated_gettext_texts[] = array( 'id' => $db_id, 'original' => $text, 'translated' => ( $translation != $text ) ? $translation : '', 'domain' => $domain );
569
  }
@@ -587,18 +640,52 @@ class TRP_Translation_Manager{
587
  }
588
  }
589
 
590
- if( ( !empty($TRP_LANGUAGE) && $this->settings["default-language"] != $TRP_LANGUAGE ) || ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview' ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
  $translation = '<trp-gettext data-trpgettextoriginal=\'' . $db_id . '\'>' . $translation . '</trp-gettext>';
592
  }
593
 
594
  return $translation;
595
  }
596
 
 
 
 
 
 
 
 
 
597
  function process_gettext_strings_with_context( $translation, $text, $context, $domain ){
598
  $translation = $this->process_gettext_strings( $translation, $text, $domain );
599
  return $translation;
600
  }
601
-
 
 
 
 
 
 
 
 
 
602
  function process_ngettext_strings($translation, $single, $plural, $number, $domain){
603
  if( $number == 1 )
604
  $translation = $this->process_gettext_strings( $translation, $single, $domain );
@@ -608,11 +695,24 @@ class TRP_Translation_Manager{
608
  return $translation;
609
  }
610
 
 
 
 
 
 
 
 
 
 
 
611
  function process_ngettext_strings_with_context( $translation, $single, $plural, $number, $context, $domain ){
612
  $translation = $this->process_ngettext_strings( $translation, $single, $plural, $number, $domain );
613
  return $translation;
614
  }
615
 
 
 
 
616
  function machine_translate_gettext(){
617
  /* @todo set the original language to detect and also decide if we automatically translate for the default language */
618
  global $TRP_LANGUAGE, $trp_gettext_strings_for_machine_translation;
@@ -661,6 +761,7 @@ class TRP_Translation_Manager{
661
  return $safe_text;
662
  }
663
 
 
664
  function handle_kses_functions_for_gettext( $tags ){
665
  if( is_array($tags) ){
666
  $tags['trp-gettext'] = array( 'data-trpgettextoriginal' => true );
30
  * @return bool Whether current page is part of the Translation Editor.
31
  */
32
  protected function conditions_met( $mode = 'true' ){
33
+ if ( isset( $_REQUEST['trp-edit-translation'] ) && esc_attr( $_REQUEST['trp-edit-translation'] ) == $mode ) {
34
  if ( current_user_can( 'manage_options' ) && ! is_admin() ) {
35
  return true;
36
  }else{
70
  wp_enqueue_script( 'trp-translation-manager-script', TRP_PLUGIN_URL . 'assets/js/trp-editor-script.js', array(), TRP_PLUGIN_VERSION );
71
  wp_enqueue_style( 'trp-translation-manager-style', TRP_PLUGIN_URL . 'assets/css/trp-editor-style.css', array(), TRP_PLUGIN_VERSION );
72
 
73
+ wp_enqueue_script( 'trp-translation-overlay', TRP_PLUGIN_URL . 'assets/js/trp-editor-overlay.js', array(), TRP_PLUGIN_VERSION );
74
+
75
+ $scripts_to_print = apply_filters( 'trp-scripts-for-editor', array( 'jquery', 'jquery-ui-core', 'jquery-effects-core', 'jquery-ui-resizable', 'trp-translation-manager-script', 'trp-select2-lib-js', 'trp-translation-overlay' ) );
76
+ $styles_to_print = apply_filters( 'trp-styles-for-editor', array( 'trp-translation-manager-style', 'trp-select2-lib-css', 'dashicons' /*'wp-admin', 'common', 'site-icon', 'buttons'*/ ) );
77
  wp_print_scripts( $scripts_to_print );
78
  wp_print_styles( $styles_to_print );
79
  }
282
  if( !empty( $lang_original_string_details ) ){
283
  foreach( $lang_original_string_details as $lang_original_string_detail ){
284
 
285
+ $translations = get_translations_for_domain( $lang_original_string_detail['domain'] );
286
+ $translated = $translations->translate( $lang_original_string_detail['original'] );
287
 
288
  $db_id = $this->trp_query->insert_gettext_strings( array( array('original' => $lang_original_string_detail['original'], 'translated' => $translated, 'domain' => $lang_original_string_detail['domain']) ), $language );
289
  $dictionaries[$language][] = array('id' => $db_id, 'original' => $lang_original_string_detail['original'], 'translated' => ( $translated != $lang_original_string_detail['original'] ) ? $translated : '', 'domain' => $lang_original_string_detail['domain']);
469
  * Create a global with the gettext strings that exist in the database
470
  */
471
  public function create_gettext_translated_global(){
472
+ if( !is_admin() || $this::is_ajax_on_frontend() ) {
473
  global $TRP_LANGUAGE;
474
 
475
  global $trp_translated_gettext_texts;
484
  }
485
  }
486
 
487
+ /**
488
+ * function that applies the gettext filter on frontend on different hooks depending on what we need
489
+ */
490
+ public function apply_gettext_filter_on_frontend(){
491
+ /* on ajax hooks from frontend that have the init hook ( we found WooCommerce has it ) apply it earlier */
492
+ if( $this::is_ajax_on_frontend() ){
493
+ add_action( 'init', array( $this, 'apply_gettext_filter' ), 100 );
494
+ }//otherwise start from the wp_head hook
495
+ else{
496
+ add_action( 'wp_head', array( $this, 'apply_gettext_filter' ), 100 );
497
+ }
498
+ }
499
+
500
+ /* apply the gettext filter here */
501
  public function apply_gettext_filter(){
502
+ if( !is_admin() || $this::is_ajax_on_frontend() ) {
503
  add_filter('gettext', array($this, 'process_gettext_strings'), 100, 3);
504
  add_filter('gettext_with_context', array($this, 'process_gettext_strings_with_context'), 100, 4);
505
  add_filter('ngettext', array($this, 'process_ngettext_strings'), 100, 5);
507
  }
508
  }
509
 
510
+ /**
511
+ * Function that determines if an ajax request came from the frontend
512
+ * @return bool
513
+ */
514
+ static function is_ajax_on_frontend(){
515
+ //check here for wp ajax or woocommerce ajax
516
+ if( ( defined('DOING_AJAX') && DOING_AJAX ) || ( defined('WC_DOING_AJAX') && WC_DOING_AJAX ) ){
517
+ $referer = '';
518
+ if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
519
+ $referer = wp_unslash( esc_url_raw( $_REQUEST['_wp_http_referer'] ) );
520
+ elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) )
521
+ $referer = wp_unslash( esc_url_raw( $_SERVER['HTTP_REFERER'] ) );
522
+
523
+ //if the request did not come from the admin set propper variables for the request (being processed in ajax they got lost) and return true
524
+ if( ( strpos( $referer, admin_url() ) === false ) ){
525
+ TRP_Translation_Manager::set_vars_in_frontend_ajax_request( $referer );
526
+ return true;
527
+ }
528
+ }
529
+
530
+ return false;
531
+ }
532
+
533
+ /**
534
+ * Function that sets the needed vars in the ajax request. Beeing ajax the globals got reset and also the REQUEST globals
535
+ * @param $referer
536
+ */
537
+ static function set_vars_in_frontend_ajax_request( $referer ){
538
+
539
+ /* for our own actions don't do nothing */
540
+ if( isset( $_REQUEST['action'] ) && strpos($_REQUEST['action'], 'trp_') === 0 )
541
+ return;
542
+
543
+ /* if the request came from preview mode make sure to keep it */
544
+ if( strpos( $referer, 'trp-edit-translation=preview' ) !== false && !isset( $_REQUEST['trp-edit-translation'] ) ) {
545
+ $_REQUEST['trp-edit-translation'] = 'preview';
546
+ }
547
+
548
+ global $TRP_LANGUAGE;
549
+ $trp = TRP_Translate_Press::get_trp_instance();
550
+ $url_converter = $trp->get_component( 'url_converter' );
551
+ $TRP_LANGUAGE = $url_converter ->get_lang_from_url_string($referer);
552
+ if( empty( $TRP_LANGUAGE ) ) {
553
+ $settings_obj = new TRP_Settings();
554
+ $settings = $settings_obj->get_settings();
555
+ $TRP_LANGUAGE = $settings["default-language"];
556
+ }
557
+ }
558
+
559
 
560
  /**
561
  * Function that replaces the translations with the ones in the database if they are differnt, wrapps the texts in the html and
572
  if( count( $this->settings['publish-languages'] ) <= 1 )
573
  return $translation;
574
 
575
+ if( ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'true' ) || $domain == TRP_PLUGIN_SLUG )
576
  return $translation;
577
 
578
+ /* for our own actions don't do nothing */
579
+ if( isset( $_REQUEST['action'] ) && strpos($_REQUEST['action'], 'trp_') === 0 )
580
+ return $translation;
581
 
582
+
583
+ if ( !defined( 'DOING_AJAX' ) || $this::is_ajax_on_frontend() ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
 
585
  global $trp_translated_gettext_texts, $trp_all_gettext_texts;
586
  $found_in_db = false;
605
  $found_in_db = true;
606
  /* update the db if a translation appeared in the po file later */
607
  if( empty( $trp_translated_gettext_text['translated'] ) && $translation != $text ) {
608
+ $this->trp_query->update_gettext_strings( array( array( 'id' => $db_id, 'original' => $text, 'translated' => $translation, 'domain' => $domain), 'status' => TRP_Query::HUMAN_REVIEWED ), get_locale() );
609
  }
610
 
611
  break;
616
  if( !$found_in_db ){
617
  if( !in_array( array('original' => $text, 'translated' => $translation, 'domain' => $domain), $trp_all_gettext_texts ) ) {
618
  $trp_all_gettext_texts[] = array('original' => $text, 'translated' => $translation, 'domain' => $domain);
619
+ $db_id = $this->trp_query->insert_gettext_strings( array( array('original' => $text, 'translated' => $translation, 'domain' => $domain) ), get_locale() );
620
  /* insert it in the global of translated because now it is in the database */
621
  $trp_translated_gettext_texts[] = array( 'id' => $db_id, 'original' => $text, 'translated' => ( $translation != $text ) ? $translation : '', 'domain' => $domain );
622
  }
640
  }
641
  }
642
 
643
+ $callstack_functions = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
644
+ if( !empty( $callstack_functions ) ){
645
+ foreach( $callstack_functions as $callstack_function ){
646
+ if( $callstack_function['function'] == 'wp_enqueue_script' ||
647
+ $callstack_function['function'] == 'wp_enqueue_scripts' ||
648
+ $callstack_function['function'] == 'wp_editor' ||
649
+ $callstack_function['function'] == 'wp_enqueue_media' ||
650
+ $callstack_function['function'] == 'wp_register_script' ||
651
+ $callstack_function['function'] == 'wp_print_scripts'||
652
+ $callstack_function['function'] == 'wp_localize_script'||
653
+ $callstack_function['function'] == 'wp_print_media_templates'
654
+ ) {
655
+ return $translation;
656
+ }
657
+ }
658
+ }
659
+
660
+ if( ( !empty($TRP_LANGUAGE) && $this->settings["default-language"] != $TRP_LANGUAGE ) || ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) )
661
  $translation = '<trp-gettext data-trpgettextoriginal=\'' . $db_id . '\'>' . $translation . '</trp-gettext>';
662
  }
663
 
664
  return $translation;
665
  }
666
 
667
+ /**
668
+ * Function that filters gettext strings with context _x
669
+ * @param $translation
670
+ * @param $text
671
+ * @param $context
672
+ * @param $domain
673
+ * @return string
674
+ */
675
  function process_gettext_strings_with_context( $translation, $text, $context, $domain ){
676
  $translation = $this->process_gettext_strings( $translation, $text, $domain );
677
  return $translation;
678
  }
679
+
680
+ /**
681
+ * function that filters the _n translations
682
+ * @param $translation
683
+ * @param $single
684
+ * @param $plural
685
+ * @param $number
686
+ * @param $domain
687
+ * @return string
688
+ */
689
  function process_ngettext_strings($translation, $single, $plural, $number, $domain){
690
  if( $number == 1 )
691
  $translation = $this->process_gettext_strings( $translation, $single, $domain );
695
  return $translation;
696
  }
697
 
698
+ /**
699
+ * function that filters the _nx translations
700
+ * @param $translation
701
+ * @param $single
702
+ * @param $plural
703
+ * @param $number
704
+ * @param $context
705
+ * @param $domain
706
+ * @return string
707
+ */
708
  function process_ngettext_strings_with_context( $translation, $single, $plural, $number, $context, $domain ){
709
  $translation = $this->process_ngettext_strings( $translation, $single, $plural, $number, $domain );
710
  return $translation;
711
  }
712
 
713
+ /**
714
+ * function that machine translates gettext strings
715
+ */
716
  function machine_translate_gettext(){
717
  /* @todo set the original language to detect and also decide if we automatically translate for the default language */
718
  global $TRP_LANGUAGE, $trp_gettext_strings_for_machine_translation;
761
  return $safe_text;
762
  }
763
 
764
+ /* let the trp-gettext wrap and data-trpgettextoriginal pass through kses filters */
765
  function handle_kses_functions_for_gettext( $tags ){
766
  if( is_array($tags) ){
767
  $tags['trp-gettext'] = array( 'data-trpgettextoriginal' => true );
includes/class-translation-render.php CHANGED
@@ -25,9 +25,11 @@ class TRP_Translation_Render{
25
  */
26
  public function start_output_buffer(){
27
  global $TRP_LANGUAGE;
28
- if( is_admin() ||
29
- ( $TRP_LANGUAGE == $this->settings['default-language'] && ( ! isset( $_GET['trp-edit-translation'] ) || ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] != 'preview' ) ) ) ||
30
- ( isset( $_GET['trp-edit-translation']) && $_GET['trp-edit-translation'] == 'true' ) || defined( 'WC_DOING_AJAX' ) ) {
 
 
31
  return;
32
  }
33
 
@@ -44,7 +46,7 @@ class TRP_Translation_Render{
44
  global $TRP_LANGUAGE;
45
  if ( in_array( $TRP_LANGUAGE, $this->settings['translation-languages'] ) ) {
46
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ){
47
- if ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview' ) {
48
  foreach ($this->settings['translation-languages'] as $language) {
49
  if ($language != $TRP_LANGUAGE) {
50
  // return the first language not default. only used for preview mode
@@ -189,6 +191,42 @@ class TRP_Translation_Render{
189
  return $output;
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  $no_translate_attribute = 'data-no-translation';
193
 
194
  $translateable_strings = array();
@@ -223,18 +261,19 @@ class TRP_Translation_Render{
223
  foreach( $trp_rows as $level ){
224
  foreach( $level as $row ){
225
  $original_gettext_translation_id = $row->getAttribute('data-trpgettextoriginal');
226
- if( count( $row->parent()->children ) == 1 ){
 
227
  $row->outertext = $row->innertext();
228
  $row->parent()->setAttribute('data-no-translation', '');
229
  // we are in the editor
230
- if (isset($_GET['trp-edit-translation']) && $_GET['trp-edit-translation'] == 'preview') {
231
  //move up the data-trpgettextoriginal attribute
232
  $row->parent()->setAttribute('data-trpgettextoriginal', $original_gettext_translation_id);
233
  }
234
  }
235
  else{
236
  $row->outertext = '<trp-wrap class="trp-wrap" data-no-translation';
237
- if (isset($_GET['trp-edit-translation']) && $_GET['trp-edit-translation'] == 'preview') {
238
  $row->outertext .= ' data-trpgettextoriginal="'. $original_gettext_translation_id .'"';
239
  }
240
  $row->outertext .= '>'.$row->innertext().'</trp-wrap>';
@@ -255,7 +294,7 @@ class TRP_Translation_Render{
255
  if( !$row->has_child() ){// if the node doesn't have children set the needed attributes, else it means that there are other nodes inside so probably they are the ones displayed
256
  $row->setAttribute('data-no-translation', '');
257
  // we are in the editor
258
- if (isset($_GET['trp-edit-translation']) && $_GET['trp-edit-translation'] == 'preview') {
259
  $original_gettext_translation_id = $nfv_row->getAttribute('data-trpgettextoriginal');
260
  $row->setAttribute('data-trpgettextoriginal', $original_gettext_translation_id);
261
  }
@@ -318,7 +357,7 @@ class TRP_Translation_Render{
318
 
319
  $translated_strings = $this->process_strings( $translateable_strings, $language_code );
320
 
321
- $preview_mode = isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview';
322
  if ( $preview_mode ) {
323
  $translated_string_ids = $this->trp_query->get_string_ids($translateable_strings, $language_code);
324
  }
@@ -609,7 +648,7 @@ class TRP_Translation_Render{
609
 
610
  global $TRP_LANGUAGE;
611
 
612
- if ( $TRP_LANGUAGE != $this->settings['default-language'] || ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview' ) ) {
613
  $language_to_query = $TRP_LANGUAGE;
614
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ) {
615
  foreach ($this->settings['translation-languages'] as $language) {
@@ -626,7 +665,7 @@ class TRP_Translation_Render{
626
  'trp_original_language' => $this->settings['default-language'],
627
  'trp_current_language' => $TRP_LANGUAGE
628
  );
629
- if ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview' ) {
630
  $trp_data['trp_ajax_url'] = $trp_data['trp_wp_ajax_url'];
631
  }
632
  wp_enqueue_script('trp-dynamic-translator', TRP_PLUGIN_URL . 'assets/js/trp-translate-dom-changes.js', array('jquery', 'trp-language-switcher'), TRP_PLUGIN_VERSION );
25
  */
26
  public function start_output_buffer(){
27
  global $TRP_LANGUAGE;
28
+ if( TRP_Translation_Manager::is_ajax_on_frontend() ){
29
+ //in this case move forward
30
+ }else if( is_admin() ||
31
+ ( $TRP_LANGUAGE == $this->settings['default-language'] && ( ! isset( $_REQUEST['trp-edit-translation'] ) || ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] != 'preview' ) ) ) ||
32
+ ( isset( $_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'true' ) ) {
33
  return;
34
  }
35
 
46
  global $TRP_LANGUAGE;
47
  if ( in_array( $TRP_LANGUAGE, $this->settings['translation-languages'] ) ) {
48
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ){
49
+ if ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) {
50
  foreach ($this->settings['translation-languages'] as $language) {
51
  if ($language != $TRP_LANGUAGE) {
52
  // return the first language not default. only used for preview mode
191
  return $output;
192
  }
193
 
194
+
195
+ /* if there is an ajax request and we have a json response we need to parse it and only translate the nodes that contain html */
196
+ if( TRP_Translation_Manager::is_ajax_on_frontend() ) {
197
+
198
+ /* if it's one of our own ajax calls don't do nothing */
199
+ if( !empty( $_REQUEST['action'] ) && strpos( $_REQUEST['action'], 'trp_' ) === 0 ){
200
+ return $output;
201
+ }
202
+
203
+ //check if we have a json response
204
+ if (is_array($json_array = json_decode($output, true))) {
205
+ if (!empty($json_array)) {
206
+ foreach ($json_array as $key => $value) {
207
+ if (!empty($value)) {
208
+ if (!is_array($value)) { //if the current element is not an array check if it a html text and translate
209
+ if (html_entity_decode((string)$value) != strip_tags(html_entity_decode((string)$value))) {
210
+ $json_array[$key] = $this->translate_page(stripslashes($value));
211
+ }
212
+ } else {//look for the html elements
213
+ foreach( $value as $k => $v ){
214
+ if( !empty( $v ) ) {
215
+ if (!is_array($v)) {
216
+ if (html_entity_decode((string)$v) != strip_tags(html_entity_decode((string)$v))) {
217
+ $json_array[$key][$k] = $this->translate_page(stripslashes($v));
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ return json_encode($json_array);
227
+ }
228
+ }
229
+
230
  $no_translate_attribute = 'data-no-translation';
231
 
232
  $translateable_strings = array();
261
  foreach( $trp_rows as $level ){
262
  foreach( $level as $row ){
263
  $original_gettext_translation_id = $row->getAttribute('data-trpgettextoriginal');
264
+ /* Parent node has no other children and no other innertext besides the current node */
265
+ if( count( $row->parent()->children ) == 1 && $row->parent()->innertext == $row->outertext ){
266
  $row->outertext = $row->innertext();
267
  $row->parent()->setAttribute('data-no-translation', '');
268
  // we are in the editor
269
+ if (isset($_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'preview') {
270
  //move up the data-trpgettextoriginal attribute
271
  $row->parent()->setAttribute('data-trpgettextoriginal', $original_gettext_translation_id);
272
  }
273
  }
274
  else{
275
  $row->outertext = '<trp-wrap class="trp-wrap" data-no-translation';
276
+ if (isset($_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'preview') {
277
  $row->outertext .= ' data-trpgettextoriginal="'. $original_gettext_translation_id .'"';
278
  }
279
  $row->outertext .= '>'.$row->innertext().'</trp-wrap>';
294
  if( !$row->has_child() ){// if the node doesn't have children set the needed attributes, else it means that there are other nodes inside so probably they are the ones displayed
295
  $row->setAttribute('data-no-translation', '');
296
  // we are in the editor
297
+ if (isset($_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'preview') {
298
  $original_gettext_translation_id = $nfv_row->getAttribute('data-trpgettextoriginal');
299
  $row->setAttribute('data-trpgettextoriginal', $original_gettext_translation_id);
300
  }
357
 
358
  $translated_strings = $this->process_strings( $translateable_strings, $language_code );
359
 
360
+ $preview_mode = isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview';
361
  if ( $preview_mode ) {
362
  $translated_string_ids = $this->trp_query->get_string_ids($translateable_strings, $language_code);
363
  }
648
 
649
  global $TRP_LANGUAGE;
650
 
651
+ if ( $TRP_LANGUAGE != $this->settings['default-language'] || ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) ) {
652
  $language_to_query = $TRP_LANGUAGE;
653
  if ( $TRP_LANGUAGE == $this->settings['default-language'] ) {
654
  foreach ($this->settings['translation-languages'] as $language) {
665
  'trp_original_language' => $this->settings['default-language'],
666
  'trp_current_language' => $TRP_LANGUAGE
667
  );
668
+ if ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) {
669
  $trp_data['trp_ajax_url'] = $trp_data['trp_wp_ajax_url'];
670
  }
671
  wp_enqueue_script('trp-dynamic-translator', TRP_PLUGIN_URL . 'assets/js/trp-translate-dom-changes.js', array('jquery', 'trp-language-switcher'), TRP_PLUGIN_VERSION );
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.0.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.0.2
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  License: GPL2
partials/addons-settings-page.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="trp-addons-page" class="wrap">
2
+
3
+ <h1> <?php _e( 'TranslatePress Settings', TRP_PLUGIN_SLUG );?></h1>
4
+ <?php do_action ( 'trp_settings_navigation_tabs' ); ?>
5
+
6
+ <div class="grid feat-header">
7
+ <div class="grid-cell">
8
+ <h2>Advanced Addons</h2>
9
+ <p>These addons extend your translation plugin and are available in the Personal, Plus and Professional plans.</p>
10
+ </div>
11
+ </div>
12
+
13
+ <div class="grid">
14
+ <div class="grid-cell" style="overflow:hidden;">
15
+ <a href="https://translatepress.com/pricing/" target="_blank"><img src="<?php echo plugins_url('../assets/images/seo_icon_translatepress.png', __FILE__) ?>" alt="SEO" style="float: left; margin: 0 1.5rem 1.5rem 0;"></a>
16
+ <h3><a href="https://translatepress.com/pricing/" target="_blank">SEO Pack</a></h3>
17
+ <p>SEO support for page slug, page title, description and facebook and twitter social graph information. The HTML lang attribute is properly set.</p>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="grid">
22
+ <div class="grid-cell" style="overflow:hidden;">
23
+ <a href="https://translatepress.com/pricing/" target="_blank"><img src="<?php echo plugins_url('../assets/images/multiple_lang_icon.png', __FILE__) ?>" alt="Multiple Languages" style="float: left; margin: 0 1.5rem 1.5rem 0;"></a>
24
+ <h3><a href="https://translatepress.com/pricing/" target="_blank">Multiple Languages</a></h3>
25
+ <p>Add as many languages as you need for your project to go global.<br>
26
+ Publish your language only when all your translations are done. </p>
27
+ </div>
28
+ </div>
29
+
30
+ </div>
partials/translation-manager.php CHANGED
@@ -41,7 +41,7 @@
41
  <div id="trp-controls">
42
  <div class="trp-controls-container">
43
  <div id="trp-close-save">
44
- <a id="trp-controls-close" href="#">&times;</a>
45
  <div id="trp-save-container">
46
  <span id="trp-translation-saved" style="display: none"><?php _e( 'Saved!', TRP_PLUGIN_SLUG ); ?></span>
47
  <span class="trp-ajax-loader" style="display: none" id="trp-string-saved-ajax-loader">
@@ -122,6 +122,7 @@
122
  <iframe id="trp-preview-iframe" onload="trpEditor.initialize();" src="<?php echo add_query_arg( 'trp-edit-translation', 'preview', $current_url );?>" width="100%" height="100%"></iframe>
123
  </div>
124
  </div>
 
125
  </body>
126
  </html>
127
 
41
  <div id="trp-controls">
42
  <div class="trp-controls-container">
43
  <div id="trp-close-save">
44
+ <a id="trp-controls-close" href="#"></a>
45
  <div id="trp-save-container">
46
  <span id="trp-translation-saved" style="display: none"><?php _e( 'Saved!', TRP_PLUGIN_SLUG ); ?></span>
47
  <span class="trp-ajax-loader" style="display: none" id="trp-string-saved-ajax-loader">
122
  <iframe id="trp-preview-iframe" onload="trpEditor.initialize();" src="<?php echo add_query_arg( 'trp-edit-translation', 'preview', $current_url );?>" width="100%" height="100%"></iframe>
123
  </div>
124
  </div>
125
+
126
  </body>
127
  </html>
128
 
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
5
  Requires at least: 3.1.0
6
  Tested up to: 4.8.2
7
- Stable tag: 1.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -104,6 +104,12 @@ For more information please check out [TranslatePress documentation](https://tra
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
 
107
  = 1.0.1 =
108
  * Fixed incorrect blog prefix name for Multisite subsites on admin_bar gettext hook.
109
  * Fixed Translate Page admin bar button sometimes not having the correct url for entering TP Editor Mode
4
  Tags: translate, translation, multilingual, automatic translation, front-end translation, google translate
5
  Requires at least: 3.1.0
6
  Tested up to: 4.8.2
7
+ Stable tag: 1.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
104
 
105
  == Changelog ==
106
 
107
+ = 1.0.2 =
108
+ * Translation interface improvements
109
+ * Fixed issues with strings loaded with ajax
110
+ * Added an addon page
111
+ * Fixed bug with gettext node accidentally wrapping another string too.
112
+
113
  = 1.0.1 =
114
  * Fixed incorrect blog prefix name for Multisite subsites on admin_bar gettext hook.
115
  * Fixed Translate Page admin bar button sometimes not having the correct url for entering TP Editor Mode