Version Description
- Implemented View As "Logged out user" functionality so you can translate strings that show only for logged out users
- Allow slug edit for default language
- Fixed an issue with the dropdown of translation strings when there were unsaved changes and the dropdown disconected from the textarea
- Prevent translate editor icon pencil to exit the translation iframe
- Fixed translating via the next/prev buttons that reset the position in the translation string list
- Refactor the way we are generating the language url for the language switcher when we don't have a variable available
Download this release
Release Info
| Developer | madalin.ungureanu |
| Plugin | |
| Version | 1.1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.9 to 1.1.0
- assets/css/trp-editor-style.css +21 -3
- assets/js/trp-back-end-script.js +73 -21
- assets/js/trp-editor-script.js +122 -8
- assets/js/trp-floater-language-switcher.js +0 -10
- assets/js/trp-iframe-preview-script.js +7 -0
- class-translate-press.php +4 -1
- includes/class-language-switcher.php +1 -2
- includes/class-settings.php +12 -56
- includes/class-translation-manager.php +42 -0
- includes/class-url-converter.php +7 -11
- index.php +1 -1
- partials/main-settings-language-selector.php +83 -0
- partials/translation-manager.php +20 -0
- readme.txt +9 -1
assets/css/trp-editor-style.css
CHANGED
|
@@ -142,15 +142,33 @@ iframe#trp-preview-iframe {
|
|
| 142 |
font-size: 14px;
|
| 143 |
padding: 3px;
|
| 144 |
}
|
| 145 |
-
#trp-language-select {
|
| 146 |
-
|
| 147 |
-
}
|
| 148 |
|
| 149 |
.string-selector-description{
|
| 150 |
font-size: 12px;
|
| 151 |
}
|
| 152 |
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
/*
|
| 142 |
font-size: 14px;
|
| 143 |
padding: 3px;
|
| 144 |
}
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
.string-selector-description{
|
| 147 |
font-size: 12px;
|
| 148 |
}
|
| 149 |
|
| 150 |
|
| 151 |
+
/*
|
| 152 |
+
View as Dropdown
|
| 153 |
+
*/
|
| 154 |
+
#trp-view-as{
|
| 155 |
+
clear:both;
|
| 156 |
+
padding-top:15px;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
#trp-view-as-description{
|
| 160 |
+
padding-bottom: 10px;
|
| 161 |
+
color: black;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
#trp-view-as-select{
|
| 165 |
+
width: 100%;
|
| 166 |
+
margin-bottom: 30px;
|
| 167 |
+
font-size: 14px;
|
| 168 |
+
padding: 3px;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
|
| 173 |
|
| 174 |
/*
|
assets/js/trp-back-end-script.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
/**
|
| 2 |
-
* Script used in Settings Page.
|
| 3 |
*/
|
| 4 |
-
function TRP_Settings() {
|
| 5 |
|
|
|
|
| 6 |
var _this = this;
|
|
|
|
|
|
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Initialize select to become select2
|
|
@@ -15,32 +17,82 @@ function TRP_Settings() {
|
|
| 15 |
});
|
| 16 |
};
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
url_slug.attr( 'name', 'trp_settings[url-slugs][' + selected_language + ']').val( '' ).val( trp_iso_codes[selected_language] );
|
| 27 |
};
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
*/
|
| 32 |
-
this.initialize = function(){
|
| 33 |
-
_this.initialize_select2();
|
| 34 |
-
jQuery( '#trp-translation-language' ).on( 'change', _this.update_translation_language );
|
| 35 |
};
|
| 36 |
|
| 37 |
-
this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
-
var
|
| 42 |
|
| 43 |
-
// Initialize the
|
| 44 |
jQuery( function() {
|
| 45 |
-
|
| 46 |
});
|
|
|
| 1 |
/**
|
| 2 |
+
* Script used in Settings Page to change the language selector and slugs.
|
| 3 |
*/
|
|
|
|
| 4 |
|
| 5 |
+
function TRP_Settings_Language_Selector() {
|
| 6 |
var _this = this;
|
| 7 |
+
var duplicate_url_error_message;
|
| 8 |
+
var iso_codes;
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Initialize select to become select2
|
| 17 |
});
|
| 18 |
};
|
| 19 |
|
| 20 |
+
this.get_default_url_slug = function( new_language ){
|
| 21 |
+
var return_slug = iso_codes[new_language];
|
| 22 |
+
var url_slugs = _this.get_existing_url_slugs();
|
| 23 |
+
url_slugs.push( return_slug );
|
| 24 |
+
if ( has_duplicates ( url_slugs ) ){
|
| 25 |
+
return_slug = new_language;
|
| 26 |
+
}
|
| 27 |
+
return return_slug.toLowerCase();
|
|
|
|
| 28 |
};
|
| 29 |
|
| 30 |
+
this.add_language = function(){
|
| 31 |
+
jQuery(".trp-upsell-multiple-languages").show('fast');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
};
|
| 33 |
|
| 34 |
+
this.update_default_language = function(){
|
| 35 |
+
var selected_language = jQuery( '#trp-default-language').val();
|
| 36 |
+
jQuery( '.trp-hidden-default-language' ).val( selected_language );
|
| 37 |
+
jQuery( '.trp-translation-published[disabled]' ).val( selected_language );
|
| 38 |
+
jQuery( '.trp-translation-language[disabled]').val( selected_language ).trigger( 'change' );
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
function has_duplicates(array) {
|
| 42 |
+
var valuesSoFar = Object.create(null);
|
| 43 |
+
for (var i = 0; i < array.length; ++i) {
|
| 44 |
+
var value = array[i];
|
| 45 |
+
if (value in valuesSoFar) {
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
valuesSoFar[value] = true;
|
| 49 |
+
}
|
| 50 |
+
return false;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
this.get_existing_url_slugs = function(){
|
| 54 |
+
var url_slugs = [];
|
| 55 |
+
jQuery( '.trp-language-slug' ).each( function (){
|
| 56 |
+
url_slugs.push( jQuery( this ).val().toLowerCase() );
|
| 57 |
+
} );
|
| 58 |
+
return url_slugs;
|
| 59 |
+
};
|
| 60 |
|
| 61 |
+
this.check_unique_url_slugs = function (event){
|
| 62 |
+
var url_slugs = _this.get_existing_url_slugs();
|
| 63 |
+
if ( has_duplicates(url_slugs)){
|
| 64 |
+
alert( duplicate_url_error_message );
|
| 65 |
+
event.preventDefault();
|
| 66 |
+
}
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
this.update_url_slug_and_status = function ( event ) {
|
| 70 |
+
var select = jQuery( event.target );
|
| 71 |
+
var new_language = select.val();
|
| 72 |
+
var row = jQuery( select ).parents( '.trp-language' ) ;
|
| 73 |
+
row.find( '.trp-language-slug' ).attr( 'name', 'trp_settings[url-slugs][' + new_language + ']').val( '' ).val( _this.get_default_url_slug( new_language ) );
|
| 74 |
+
row.find( '.trp-translation-published' ).val( new_language );
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
this.initialize = function () {
|
| 78 |
+
this.initialize_select2();
|
| 79 |
+
duplicate_url_error_message = trp_url_slugs_info['error_message_duplicate_slugs'];
|
| 80 |
+
iso_codes = trp_url_slugs_info['iso_codes'];
|
| 81 |
+
|
| 82 |
+
jQuery( '#trp-sortable-languages' ).sortable({ handle: '.trp-sortable-handle' });
|
| 83 |
+
jQuery( '#trp-add-language' ).click( _this.add_language );
|
| 84 |
+
jQuery( '#trp-default-language' ).on( 'change', _this.update_default_language );
|
| 85 |
+
jQuery( "form[action='options.php']").on ( 'submit', _this.check_unique_url_slugs );
|
| 86 |
+
jQuery( '#trp-languages-table' ).on( 'change', '.trp-translation-language', _this.update_url_slug_and_status );
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
this.initialize();
|
| 90 |
}
|
| 91 |
|
| 92 |
+
var trpSettingsLanguages;
|
| 93 |
|
| 94 |
+
// Initialize the Translate Press Settings after jQuery is ready
|
| 95 |
jQuery( function() {
|
| 96 |
+
trpSettingsLanguages = new TRP_Settings_Language_Selector();
|
| 97 |
});
|
| 98 |
+
|
assets/js/trp-editor-script.js
CHANGED
|
@@ -32,11 +32,42 @@ function TRP_Editor(){
|
|
| 32 |
var language = select.value;
|
| 33 |
var link = jQuery( '#trp-preview-iframe' ).contents().find('link[hreflang=' + language + ']').first().attr('href');
|
| 34 |
if ( link != undefined ){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
select.form.action = link;
|
| 36 |
select.form.submit();
|
| 37 |
}
|
| 38 |
};
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
/**
|
| 41 |
* Initialize string finding, string select dropdown and change tracker.
|
| 42 |
*/
|
|
@@ -67,12 +98,15 @@ function TRP_Editor(){
|
|
| 67 |
var location = document.getElementById("trp-preview-iframe").contentWindow.location.href;
|
| 68 |
var close_url = location.replace( '&trp-edit-translation=preview', '' );
|
| 69 |
close_url = close_url.replace( '?trp-edit-translation=preview', '?' );
|
| 70 |
-
if ( close_url[close_url.length -1] == '?' ){
|
| 71 |
-
close_url = close_url.slice(0, -1);
|
| 72 |
-
}
|
| 73 |
|
| 74 |
/* remove the lang atribute from url. TODO maybe use this same method for trp-edit-translation ? */
|
| 75 |
close_url = _this.remove_url_parameter( close_url, 'lang' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
close_button.attr( 'href', close_url );
|
| 78 |
location = location.replace( 'trp-edit-translation=preview', 'trp-edit-translation=true' );
|
|
@@ -339,6 +373,40 @@ function TRP_Editor(){
|
|
| 339 |
}
|
| 340 |
};
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
/**
|
| 343 |
* Resizing preview window.
|
| 344 |
*
|
|
@@ -386,7 +454,7 @@ function TRP_Editor(){
|
|
| 386 |
if ( _this.change_tracker.check_unsaved_changes() ) {
|
| 387 |
return;
|
| 388 |
}
|
| 389 |
-
next_option_value = jQuery(
|
| 390 |
if( typeof next_option_value != "undefined" && next_option_value != '' ) {
|
| 391 |
_this.jquery_string_selector.val(next_option_value).trigger('change');
|
| 392 |
}
|
|
@@ -409,8 +477,16 @@ function TRP_Editor(){
|
|
| 409 |
if (placeholder_text != '') {
|
| 410 |
placeholder_text = 'Select string to translate...';
|
| 411 |
}
|
| 412 |
-
_this.jquery_string_selector.select2({ placeholder: placeholder_text, templateResult: format_option });
|
| 413 |
-
jQuery( '#trp-language-select' ).select2();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
}
|
| 415 |
|
| 416 |
/**
|
|
@@ -453,6 +529,16 @@ function TRP_Editor(){
|
|
| 453 |
return option;
|
| 454 |
}
|
| 455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
add_event_handlers();
|
| 457 |
}
|
| 458 |
|
|
@@ -706,8 +792,10 @@ function TRP_String( language, array_index ){
|
|
| 706 |
_this.wrap_special_html_elements();
|
| 707 |
trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
|
| 708 |
jquery_object.prepend(trpEditor.edit_translation_button);
|
| 709 |
-
|
| 710 |
}
|
|
|
|
|
|
|
|
|
|
| 711 |
trpEditor.edit_translation_button.off( 'click' );
|
| 712 |
trpEditor.edit_translation_button.on( 'click', function(e){
|
| 713 |
e.preventDefault();
|
|
@@ -782,6 +870,24 @@ function TRP_Lister( current_dictionary ) {
|
|
| 782 |
var dictionary = current_dictionary;
|
| 783 |
var category_array;
|
| 784 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
|
| 786 |
/**
|
| 787 |
* A string has been selected from the list.
|
|
@@ -804,6 +910,8 @@ function TRP_Lister( current_dictionary ) {
|
|
| 804 |
* Refresh list with new strings.
|
| 805 |
*/
|
| 806 |
this.reload_list = function (){
|
|
|
|
|
|
|
| 807 |
category_array = dictionary.get_categories();
|
| 808 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).prevAll(":not(.default-option)").remove();
|
| 809 |
/* add the normal strings before the trp-gettext-strings-optgroup optiongroup so it doesn't matter which ajax finishes first */
|
|
@@ -820,18 +928,23 @@ function TRP_Lister( current_dictionary ) {
|
|
| 820 |
}
|
| 821 |
}
|
| 822 |
}
|
| 823 |
-
|
| 824 |
jquery_string_selector.on( 'change', _this.select_string );
|
|
|
|
|
|
|
| 825 |
};
|
| 826 |
|
| 827 |
|
| 828 |
this.add_gettext_strings = function (){
|
|
|
|
|
|
|
| 829 |
gettext_category = dictionary;
|
| 830 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).nextAll().remove();
|
| 831 |
for ( var i in gettext_category){
|
| 832 |
var original = gettext_category[i].original;
|
| 833 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).after(jQuery('<option></option>').attr( 'value', 'gettext-'+gettext_category[i].id ).text( _this.format_text( original )).attr( 'title', gettext_category[i].domain ).attr( 'data-trp-gettext-id', gettext_category[i].id ) );
|
| 834 |
}
|
|
|
|
|
|
|
| 835 |
};
|
| 836 |
|
| 837 |
/**
|
|
@@ -1133,6 +1246,7 @@ jQuery(function(){
|
|
| 1133 |
else {
|
| 1134 |
jQuery(this).prepend(trpEditor.edit_translation_button);
|
| 1135 |
}
|
|
|
|
| 1136 |
trpEditor.edit_translation_button.off( 'click' );
|
| 1137 |
trpEditor.edit_translation_button.on( 'click', function(e){
|
| 1138 |
e.preventDefault();
|
| 32 |
var language = select.value;
|
| 33 |
var link = jQuery( '#trp-preview-iframe' ).contents().find('link[hreflang=' + language + ']').first().attr('href');
|
| 34 |
if ( link != undefined ){
|
| 35 |
+
|
| 36 |
+
/* pass on trp-view-as parameters to all links that also have preview parameter */
|
| 37 |
+
if( typeof URL == 'function' && window.location.href.search("trp-view-as=") >= 0 && window.location.href.search("trp-view-as-nonce=") >= 0 ){
|
| 38 |
+
var currentUrl = new URL(window.location.href);
|
| 39 |
+
jQuery(select.form).append('<input type="hidden" name="trp-view-as" value="'+currentUrl.searchParams.get("trp-view-as")+'"/>');
|
| 40 |
+
jQuery(select.form).append('<input type="hidden" name="trp-view-as-nonce" value="'+currentUrl.searchParams.get("trp-view-as-nonce")+'"/>');
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
select.form.action = link;
|
| 44 |
select.form.submit();
|
| 45 |
}
|
| 46 |
};
|
| 47 |
|
| 48 |
+
/**
|
| 49 |
+
* Change view as iframe source
|
| 50 |
+
*
|
| 51 |
+
* @param select HTML Element Select with languages
|
| 52 |
+
*/
|
| 53 |
+
this.change_view_as = function( select ){
|
| 54 |
+
var view_as = select.value;
|
| 55 |
+
var view_nonce = jQuery('option:selected', select).attr('data-view-as-nonce');
|
| 56 |
+
var current_link = document.getElementById("trp-preview-iframe").contentWindow.location.href;
|
| 57 |
+
current_link = current_link.replace( 'trp-edit-translation=true', 'trp-edit-translation=preview' );
|
| 58 |
+
|
| 59 |
+
/* remove maybe previously selected values */
|
| 60 |
+
current_link = _this.remove_url_parameter( current_link, 'trp-view-as' );
|
| 61 |
+
current_link = _this.remove_url_parameter( current_link, 'trp-view-as-nonce' );
|
| 62 |
+
|
| 63 |
+
if ( current_link != undefined ){
|
| 64 |
+
if( view_as == 'current_user' )
|
| 65 |
+
jQuery( '#trp-preview-iframe' ).attr('src', current_link );
|
| 66 |
+
else
|
| 67 |
+
jQuery( '#trp-preview-iframe' ).attr('src', current_link + '&trp-view-as=' + view_as + '&trp-view-as-nonce=' + view_nonce );
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
/**
|
| 72 |
* Initialize string finding, string select dropdown and change tracker.
|
| 73 |
*/
|
| 98 |
var location = document.getElementById("trp-preview-iframe").contentWindow.location.href;
|
| 99 |
var close_url = location.replace( '&trp-edit-translation=preview', '' );
|
| 100 |
close_url = close_url.replace( '?trp-edit-translation=preview', '?' );
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
/* remove the lang atribute from url. TODO maybe use this same method for trp-edit-translation ? */
|
| 103 |
close_url = _this.remove_url_parameter( close_url, 'lang' );
|
| 104 |
+
close_url = _this.remove_url_parameter( close_url, 'trp-view-as' );
|
| 105 |
+
close_url = _this.remove_url_parameter( close_url, 'trp-view-as-nonce' );
|
| 106 |
+
|
| 107 |
+
if ( close_url[close_url.length -1] == '?' ){
|
| 108 |
+
close_url = close_url.slice(0, -1);
|
| 109 |
+
}
|
| 110 |
|
| 111 |
close_button.attr( 'href', close_url );
|
| 112 |
location = location.replace( 'trp-edit-translation=preview', 'trp-edit-translation=true' );
|
| 373 |
}
|
| 374 |
};
|
| 375 |
|
| 376 |
+
/**
|
| 377 |
+
* Update url with query string.
|
| 378 |
+
*
|
| 379 |
+
*/
|
| 380 |
+
this.update_query_string = function(key, value, url) {
|
| 381 |
+
if (!url) url = window.location.href;
|
| 382 |
+
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
|
| 383 |
+
hash;
|
| 384 |
+
|
| 385 |
+
if (re.test(url)) {
|
| 386 |
+
if (typeof value !== 'undefined' && value !== null)
|
| 387 |
+
return url.replace(re, '$1' + key + "=" + value + '$2$3');
|
| 388 |
+
else {
|
| 389 |
+
hash = url.split('#');
|
| 390 |
+
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
|
| 391 |
+
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
|
| 392 |
+
url += '#' + hash[1];
|
| 393 |
+
return url;
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
else {
|
| 397 |
+
if (typeof value !== 'undefined' && value !== null ) {
|
| 398 |
+
var separator = url.indexOf('?') !== -1 ? '&' : '?';
|
| 399 |
+
hash = url.split('#');
|
| 400 |
+
url = hash[0] + separator + key + '=' + value;
|
| 401 |
+
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
|
| 402 |
+
url += '#' + hash[1];
|
| 403 |
+
return url;
|
| 404 |
+
}
|
| 405 |
+
else
|
| 406 |
+
return url;
|
| 407 |
+
}
|
| 408 |
+
};
|
| 409 |
+
|
| 410 |
/**
|
| 411 |
* Resizing preview window.
|
| 412 |
*
|
| 454 |
if ( _this.change_tracker.check_unsaved_changes() ) {
|
| 455 |
return;
|
| 456 |
}
|
| 457 |
+
next_option_value = jQuery('option:selected', _this.jquery_string_selector).nextAll('option').first().attr('value');
|
| 458 |
if( typeof next_option_value != "undefined" && next_option_value != '' ) {
|
| 459 |
_this.jquery_string_selector.val(next_option_value).trigger('change');
|
| 460 |
}
|
| 477 |
if (placeholder_text != '') {
|
| 478 |
placeholder_text = 'Select string to translate...';
|
| 479 |
}
|
| 480 |
+
_this.jquery_string_selector.select2({ placeholder: placeholder_text, templateResult: format_option, width: '100%' });
|
| 481 |
+
jQuery( '#trp-language-select' ).select2({ width: '100%' });
|
| 482 |
+
jQuery( '#trp-view-as-select' ).select2({ width: '100%' });
|
| 483 |
+
|
| 484 |
+
/* when we have unsaved changes prevent the strings dropdown from opening so we do not have a disconnect between the textareas and the dropdown */
|
| 485 |
+
_this.jquery_string_selector.on('select2:opening', function (e) {
|
| 486 |
+
if ( trpEditor.change_tracker.check_unsaved_changes() ) {
|
| 487 |
+
e.preventDefault();
|
| 488 |
+
}
|
| 489 |
+
});
|
| 490 |
}
|
| 491 |
|
| 492 |
/**
|
| 529 |
return option;
|
| 530 |
}
|
| 531 |
|
| 532 |
+
this.make_sure_pencil_icon_is_inside_view = function( jquery_object_highlighted ){
|
| 533 |
+
var rect = jquery_object_highlighted.getBoundingClientRect();
|
| 534 |
+
if (rect.left < 30 ){
|
| 535 |
+
var margin = - rect.left;
|
| 536 |
+
trpEditor.edit_translation_button[0].setAttribute( 'style', 'margin-left: ' + margin + 'px !important' );
|
| 537 |
+
}else{
|
| 538 |
+
trpEditor.edit_translation_button[0].removeAttribute( 'style' );
|
| 539 |
+
}
|
| 540 |
+
};
|
| 541 |
+
|
| 542 |
add_event_handlers();
|
| 543 |
}
|
| 544 |
|
| 792 |
_this.wrap_special_html_elements();
|
| 793 |
trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
|
| 794 |
jquery_object.prepend(trpEditor.edit_translation_button);
|
|
|
|
| 795 |
}
|
| 796 |
+
|
| 797 |
+
trpEditor.make_sure_pencil_icon_is_inside_view( jquery_object[0] );
|
| 798 |
+
|
| 799 |
trpEditor.edit_translation_button.off( 'click' );
|
| 800 |
trpEditor.edit_translation_button.on( 'click', function(e){
|
| 801 |
e.preventDefault();
|
| 870 |
var dictionary = current_dictionary;
|
| 871 |
var category_array;
|
| 872 |
|
| 873 |
+
/*
|
| 874 |
+
* Save current selected option in the dropdown. Should be called before we make changes in the dropdown.
|
| 875 |
+
*/
|
| 876 |
+
this.cache_selected_option = function(){
|
| 877 |
+
var selected_option = jQuery( 'option:selected', jquery_string_selector ).val();
|
| 878 |
+
if ( typeof selected_option != "undefined" && selected_option != "" ) {
|
| 879 |
+
cached_selected_option = selected_option;
|
| 880 |
+
}
|
| 881 |
+
};
|
| 882 |
+
|
| 883 |
+
/*
|
| 884 |
+
* Restore saved cached option. Should be called after we make changes in the dropdown. Otherwise the selected option will be changed to default.
|
| 885 |
+
*/
|
| 886 |
+
this.set_cached_option = function(){
|
| 887 |
+
if ( typeof cached_selected_option != "undefined" && cached_selected_option != "" ){
|
| 888 |
+
jquery_string_selector.val( cached_selected_option );
|
| 889 |
+
}
|
| 890 |
+
};
|
| 891 |
|
| 892 |
/**
|
| 893 |
* A string has been selected from the list.
|
| 910 |
* Refresh list with new strings.
|
| 911 |
*/
|
| 912 |
this.reload_list = function (){
|
| 913 |
+
_this.cache_selected_option();
|
| 914 |
+
|
| 915 |
category_array = dictionary.get_categories();
|
| 916 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).prevAll(":not(.default-option)").remove();
|
| 917 |
/* add the normal strings before the trp-gettext-strings-optgroup optiongroup so it doesn't matter which ajax finishes first */
|
| 928 |
}
|
| 929 |
}
|
| 930 |
}
|
|
|
|
| 931 |
jquery_string_selector.on( 'change', _this.select_string );
|
| 932 |
+
|
| 933 |
+
_this.set_cached_option();
|
| 934 |
};
|
| 935 |
|
| 936 |
|
| 937 |
this.add_gettext_strings = function (){
|
| 938 |
+
_this.cache_selected_option();
|
| 939 |
+
|
| 940 |
gettext_category = dictionary;
|
| 941 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).nextAll().remove();
|
| 942 |
for ( var i in gettext_category){
|
| 943 |
var original = gettext_category[i].original;
|
| 944 |
jQuery( "#trp-gettext-strings-optgroup", jquery_string_selector ).after(jQuery('<option></option>').attr( 'value', 'gettext-'+gettext_category[i].id ).text( _this.format_text( original )).attr( 'title', gettext_category[i].domain ).attr( 'data-trp-gettext-id', gettext_category[i].id ) );
|
| 945 |
}
|
| 946 |
+
|
| 947 |
+
_this.set_cached_option();
|
| 948 |
};
|
| 949 |
|
| 950 |
/**
|
| 1246 |
else {
|
| 1247 |
jQuery(this).prepend(trpEditor.edit_translation_button);
|
| 1248 |
}
|
| 1249 |
+
trpEditor.make_sure_pencil_icon_is_inside_view ( jQuery(this)[0] );
|
| 1250 |
trpEditor.edit_translation_button.off( 'click' );
|
| 1251 |
trpEditor.edit_translation_button.on( 'click', function(e){
|
| 1252 |
e.preventDefault();
|
assets/js/trp-floater-language-switcher.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
/**
|
| 2 |
-
* Change language using language select floater.
|
| 3 |
-
*
|
| 4 |
-
* @param string language_code language code
|
| 5 |
-
*/
|
| 6 |
-
function trp_floater_change_language( language_code ) {
|
| 7 |
-
if( typeof parent.trpEditor == 'undefined' ) {
|
| 8 |
-
window.location.replace(document.querySelector('link[hreflang="' + language_code + '"]').href);
|
| 9 |
-
}
|
| 10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/js/trp-iframe-preview-script.js
CHANGED
|
@@ -17,6 +17,13 @@ function TRP_Iframe_Preview(){
|
|
| 17 |
if (this.action != '' && this.href.indexOf('void(0)') === -1) {
|
| 18 |
if (is_link_previewable(this) && !this.getAttribute('href').startsWith('#')) {
|
| 19 |
this.href = update_query_string('trp-edit-translation', 'preview', this.getAttribute('href'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
} else {
|
| 21 |
jQuery(this).on('click',
|
| 22 |
function (event) {
|
| 17 |
if (this.action != '' && this.href.indexOf('void(0)') === -1) {
|
| 18 |
if (is_link_previewable(this) && !this.getAttribute('href').startsWith('#')) {
|
| 19 |
this.href = update_query_string('trp-edit-translation', 'preview', this.getAttribute('href'));
|
| 20 |
+
/* pass on trp-view-as parameters to all links that also have preview parameter */
|
| 21 |
+
if( typeof URL == 'function' && window.location.href.search("trp-view-as=") >= 0 && window.location.href.search("trp-view-as-nonce=") >= 0 ){
|
| 22 |
+
var currentUrl = new URL(window.location.href);
|
| 23 |
+
this.href = update_query_string('trp-view-as', currentUrl.searchParams.get("trp-view-as"), this.href);
|
| 24 |
+
this.href = update_query_string('trp-view-as-nonce', currentUrl.searchParams.get("trp-view-as-nonce"), this.href);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
} else {
|
| 28 |
jQuery(this).on('click',
|
| 29 |
function (event) {
|
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.0
|
| 43 |
|
| 44 |
$this->load_dependencies();
|
| 45 |
$this->initialize_components();
|
|
@@ -183,6 +183,9 @@ class TRP_Translate_Press{
|
|
| 183 |
|
| 184 |
/* hide php ors and notice when we are storing strings in db */
|
| 185 |
$this->loader->add_action( 'wp', $this->translation_render, 'trp_debug_mode_off' );
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
/**
|
| 188 |
* we need to modify the permalinks structure for woocommerce when we switch languages
|
| 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.0' );
|
| 43 |
|
| 44 |
$this->load_dependencies();
|
| 45 |
$this->initialize_components();
|
| 183 |
|
| 184 |
/* hide php ors and notice when we are storing strings in db */
|
| 185 |
$this->loader->add_action( 'wp', $this->translation_render, 'trp_debug_mode_off' );
|
| 186 |
+
|
| 187 |
+
/* ?or init ? hook here where you can change the $current_user global */
|
| 188 |
+
$this->loader->add_action( 'init', $this->translation_manager, 'trp_view_as_user' );
|
| 189 |
|
| 190 |
/**
|
| 191 |
* we need to modify the permalinks structure for woocommerce when we switch languages
|
includes/class-language-switcher.php
CHANGED
|
@@ -91,7 +91,6 @@ class TRP_Language_Switcher{
|
|
| 91 |
wp_enqueue_script('trp-language-switcher', TRP_PLUGIN_URL . 'assets/js/trp-language-switcher.js', array('jquery'), TRP_PLUGIN_VERSION );
|
| 92 |
|
| 93 |
if ( isset( $this->settings['trp-ls-floater'] ) && $this->settings['trp-ls-floater'] == 'yes' ) {
|
| 94 |
-
wp_enqueue_script('trp-floater-language-switcher-script', TRP_PLUGIN_URL . 'assets/js/trp-floater-language-switcher.js', array('jquery'), TRP_PLUGIN_VERSION );
|
| 95 |
wp_enqueue_style('trp-floater-language-switcher-style', TRP_PLUGIN_URL . 'assets/css/trp-floater-language-switcher.css', array(), TRP_PLUGIN_VERSION );
|
| 96 |
}
|
| 97 |
|
|
@@ -216,7 +215,7 @@ class TRP_Language_Switcher{
|
|
| 216 |
}
|
| 217 |
|
| 218 |
?>
|
| 219 |
-
<a href="
|
| 220 |
<?php
|
| 221 |
}
|
| 222 |
?>
|
| 91 |
wp_enqueue_script('trp-language-switcher', TRP_PLUGIN_URL . 'assets/js/trp-language-switcher.js', array('jquery'), TRP_PLUGIN_VERSION );
|
| 92 |
|
| 93 |
if ( isset( $this->settings['trp-ls-floater'] ) && $this->settings['trp-ls-floater'] == 'yes' ) {
|
|
|
|
| 94 |
wp_enqueue_style('trp-floater-language-switcher-style', TRP_PLUGIN_URL . 'assets/css/trp-floater-language-switcher.css', array(), TRP_PLUGIN_VERSION );
|
| 95 |
}
|
| 96 |
|
| 215 |
}
|
| 216 |
|
| 217 |
?>
|
| 218 |
+
<a href="<?php echo $this->url_converter->get_url_for_language($code, false); ?>" <?php echo ( isset( $_GET['trp-edit-translation'] ) && $_GET['trp-edit-translation'] == 'preview' ) ? 'data-trp-unpreviewable="trp-unpreviewable"' : '' ?> title="<?php echo $name; ?>"><?php echo ( $floater_settings['flags'] ? $this->add_flag( $code, $name ) : '' ); echo $language_label; ?></a>
|
| 219 |
<?php
|
| 220 |
}
|
| 221 |
?>
|
includes/class-settings.php
CHANGED
|
@@ -223,6 +223,9 @@ class TRP_Settings{
|
|
| 223 |
|
| 224 |
$settings['google-translate-codes'] = $this->trp_languages->get_iso_codes( $settings['publish-languages'] );
|
| 225 |
|
|
|
|
|
|
|
|
|
|
| 226 |
return apply_filters( 'trp_extra_sanitize_settings', $settings );
|
| 227 |
}
|
| 228 |
|
|
@@ -248,8 +251,8 @@ class TRP_Settings{
|
|
| 248 |
}
|
| 249 |
$default_settings = array(
|
| 250 |
'default-language' => $default,
|
| 251 |
-
'translation-languages' => array( $default ),
|
| 252 |
-
'publish-languages' => array( $default ),
|
| 253 |
'native_or_english_name' => 'english_name',
|
| 254 |
'add-subdirectory-to-default-language' => 'no',
|
| 255 |
'force-language-to-custom-links' => 'no',
|
|
@@ -258,7 +261,7 @@ class TRP_Settings{
|
|
| 258 |
'shortcode-options' => 'flags-full-names',
|
| 259 |
'menu-options' => 'flags-full-names',
|
| 260 |
'floater-options' => 'flags-full-names',
|
| 261 |
-
'url-slugs' => array( 'en_US' => 'en' ),
|
| 262 |
);
|
| 263 |
if ( 'not_set' == $settings_option ){
|
| 264 |
update_option ( 'trp_settings', $default_settings );
|
|
@@ -270,9 +273,7 @@ class TRP_Settings{
|
|
| 270 |
}
|
| 271 |
}
|
| 272 |
$settings_option = $this->check_settings_option( $settings_option, $default_settings );
|
| 273 |
-
|
| 274 |
}
|
| 275 |
-
|
| 276 |
$this->settings = $settings_option;
|
| 277 |
}
|
| 278 |
|
|
@@ -292,17 +293,18 @@ class TRP_Settings{
|
|
| 292 |
}
|
| 293 |
|
| 294 |
if ( $hook == 'settings_page_translate-press' ) {
|
| 295 |
-
wp_enqueue_script( 'trp-settings-script', TRP_PLUGIN_URL . 'assets/js/trp-back-end-script.js', array( 'jquery' ), TRP_PLUGIN_VERSION );
|
| 296 |
if ( ! $this->trp_languages ){
|
| 297 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 298 |
$this->trp_languages = $trp->get_component( 'languages' );
|
| 299 |
}
|
| 300 |
$all_language_codes = $this->trp_languages->get_all_language_codes();
|
| 301 |
$iso_codes = $this->trp_languages->get_iso_codes( $all_language_codes, false );
|
| 302 |
-
wp_localize_script( 'trp-settings-script', '
|
| 303 |
|
| 304 |
wp_enqueue_script( 'trp-select2-lib-js', TRP_PLUGIN_URL . 'assets/lib/select2-lib/dist/js/select2.min.js', array( 'jquery' ), TRP_PLUGIN_VERSION );
|
| 305 |
wp_enqueue_style( 'trp-select2-lib-css', TRP_PLUGIN_URL . 'assets/lib/select2-lib/dist/css/select2.min.css', array(), TRP_PLUGIN_VERSION );
|
|
|
|
| 306 |
}
|
| 307 |
}
|
| 308 |
|
|
@@ -319,66 +321,20 @@ class TRP_Settings{
|
|
| 319 |
$this->url_converter = $trp->get_component('url_converter');
|
| 320 |
}
|
| 321 |
$selected_language_code = '';
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
<th scope="row"> <?php _e( 'Translation Language', 'translatepress-multilingual' ) ?> </th>
|
| 325 |
-
<td>
|
| 326 |
-
<select id="trp-translation-language" name="trp_settings[translation-languages][]" class="trp-select2">
|
| 327 |
-
<option value=""><?php _e( 'Choose...', 'translatepress-multilingual' );?></option>
|
| 328 |
-
<?php foreach( $languages as $language_code => $language_name ){ ?>
|
| 329 |
-
<option value="<?php echo $language_code; ?>" <?php if ( in_array( $language_code, $this->settings['translation-languages'] ) && $language_code != $this->settings['default-language'] ) { echo 'selected'; $selected_language_code = $language_code; } ?>>
|
| 330 |
-
<?php echo $language_name; ?>
|
| 331 |
-
</option>
|
| 332 |
-
<?php }?>
|
| 333 |
-
</select>
|
| 334 |
-
<label>
|
| 335 |
-
<span id="trp-published-language"><b><?php _e( 'Slug', 'translatepress-multilingual' ); ?></b></span>
|
| 336 |
-
<input id="trp-url-slug" class="trp-language-slug" name="trp_settings[url-slugs][<?php echo $selected_language_code ?>]" type="text" style="text-transform: lowercase;" value="<?php echo $this->url_converter->get_url_slug( $selected_language_code, false ); ?>">
|
| 337 |
-
<input id="trp-active-checkbox" type="hidden" class="trp-translation-published " name="trp_settings[publish-languages][]" value="<?php echo $selected_language_code; ?>" >
|
| 338 |
-
</label>
|
| 339 |
-
<p class="description">
|
| 340 |
-
<?php _e( 'Select the language you wish to make your website available in.<br>To select multiple languages, consider upgrading to <a href="https://translatepress.com/" target="_blank" title="TranslatePress Pro">TranslatePress PRO</a>.', 'translatepress-multilingual' ); ?>
|
| 341 |
-
</p>
|
| 342 |
-
</td>
|
| 343 |
-
</tr>
|
| 344 |
-
<?php
|
| 345 |
}
|
| 346 |
|
| 347 |
/**
|
| 348 |
* Validate settings option.
|
| 349 |
*
|
|
|
|
| 350 |
* @param array $settings Settings option.
|
| 351 |
* @param array $default_settings Default settings option.
|
| 352 |
* @return array Validated settings option.
|
| 353 |
*/
|
| 354 |
public function check_settings_option( $settings, $default_settings ){
|
| 355 |
-
if ( class_exists( 'TRP_Extra_Languages' ) ){
|
| 356 |
-
// checks are made in the Add-on later
|
| 357 |
return $settings;
|
| 358 |
-
}
|
| 359 |
-
foreach ( $settings['translation-languages'] as $language_code ) {
|
| 360 |
-
if ( $settings['default-language'] != $language_code ) {
|
| 361 |
-
$translation_language = $language_code;
|
| 362 |
-
break;
|
| 363 |
-
}
|
| 364 |
-
}
|
| 365 |
-
$settings['translation-languages'] = array( $settings['default-language'] );
|
| 366 |
-
if ( !empty( $translation_language ) ){
|
| 367 |
-
$settings['translation-languages'][] = $translation_language;
|
| 368 |
-
}
|
| 369 |
-
|
| 370 |
-
foreach ( $settings['publish-languages'] as $language_code ) {
|
| 371 |
-
if ( $settings['default-language'] != $language_code ) {
|
| 372 |
-
$translation_language = $language_code;
|
| 373 |
-
break;
|
| 374 |
-
}
|
| 375 |
-
}
|
| 376 |
-
$settings['publish-languages'] = array( $settings['default-language'] );
|
| 377 |
-
if ( !empty( $translation_language ) ){
|
| 378 |
-
$settings['publish-languages'][] = $translation_language;
|
| 379 |
-
}
|
| 380 |
-
|
| 381 |
-
return $settings;
|
| 382 |
}
|
| 383 |
|
| 384 |
/**
|
| 223 |
|
| 224 |
$settings['google-translate-codes'] = $this->trp_languages->get_iso_codes( $settings['publish-languages'] );
|
| 225 |
|
| 226 |
+
// regenerate permalinks in case something changed
|
| 227 |
+
flush_rewrite_rules();
|
| 228 |
+
|
| 229 |
return apply_filters( 'trp_extra_sanitize_settings', $settings );
|
| 230 |
}
|
| 231 |
|
| 251 |
}
|
| 252 |
$default_settings = array(
|
| 253 |
'default-language' => $default,
|
| 254 |
+
'translation-languages' => array( $default, '' ),
|
| 255 |
+
'publish-languages' => array( $default, '' ),
|
| 256 |
'native_or_english_name' => 'english_name',
|
| 257 |
'add-subdirectory-to-default-language' => 'no',
|
| 258 |
'force-language-to-custom-links' => 'no',
|
| 261 |
'shortcode-options' => 'flags-full-names',
|
| 262 |
'menu-options' => 'flags-full-names',
|
| 263 |
'floater-options' => 'flags-full-names',
|
| 264 |
+
'url-slugs' => array( 'en_US' => 'en', '' ),
|
| 265 |
);
|
| 266 |
if ( 'not_set' == $settings_option ){
|
| 267 |
update_option ( 'trp_settings', $default_settings );
|
| 273 |
}
|
| 274 |
}
|
| 275 |
$settings_option = $this->check_settings_option( $settings_option, $default_settings );
|
|
|
|
| 276 |
}
|
|
|
|
| 277 |
$this->settings = $settings_option;
|
| 278 |
}
|
| 279 |
|
| 293 |
}
|
| 294 |
|
| 295 |
if ( $hook == 'settings_page_translate-press' ) {
|
| 296 |
+
wp_enqueue_script( 'trp-settings-script', TRP_PLUGIN_URL . 'assets/js/trp-back-end-script.js', array( 'jquery', 'jquery-ui-sortable' ), TRP_PLUGIN_VERSION );
|
| 297 |
if ( ! $this->trp_languages ){
|
| 298 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 299 |
$this->trp_languages = $trp->get_component( 'languages' );
|
| 300 |
}
|
| 301 |
$all_language_codes = $this->trp_languages->get_all_language_codes();
|
| 302 |
$iso_codes = $this->trp_languages->get_iso_codes( $all_language_codes, false );
|
| 303 |
+
wp_localize_script( 'trp-settings-script', 'trp_url_slugs_info', array( 'iso_codes' => $iso_codes, 'error_message_duplicate_slugs' => __( 'Error! Duplicate Url slug values.', TRP_PLUGIN_SLUG ) ) );
|
| 304 |
|
| 305 |
wp_enqueue_script( 'trp-select2-lib-js', TRP_PLUGIN_URL . 'assets/lib/select2-lib/dist/js/select2.min.js', array( 'jquery' ), TRP_PLUGIN_VERSION );
|
| 306 |
wp_enqueue_style( 'trp-select2-lib-css', TRP_PLUGIN_URL . 'assets/lib/select2-lib/dist/css/select2.min.css', array(), TRP_PLUGIN_VERSION );
|
| 307 |
+
|
| 308 |
}
|
| 309 |
}
|
| 310 |
|
| 321 |
$this->url_converter = $trp->get_component('url_converter');
|
| 322 |
}
|
| 323 |
$selected_language_code = '';
|
| 324 |
+
|
| 325 |
+
require_once TRP_PLUGIN_DIR . 'partials/main-settings-language-selector.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
}
|
| 327 |
|
| 328 |
/**
|
| 329 |
* Validate settings option.
|
| 330 |
*
|
| 331 |
+
* @deprecated
|
| 332 |
* @param array $settings Settings option.
|
| 333 |
* @param array $default_settings Default settings option.
|
| 334 |
* @return array Validated settings option.
|
| 335 |
*/
|
| 336 |
public function check_settings_option( $settings, $default_settings ){
|
|
|
|
|
|
|
| 337 |
return $settings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
|
| 340 |
/**
|
includes/class-translation-manager.php
CHANGED
|
@@ -33,6 +33,8 @@ class TRP_Translation_Manager{
|
|
| 33 |
if ( isset( $_REQUEST['trp-edit-translation'] ) && esc_attr( $_REQUEST['trp-edit-translation'] ) == $mode ) {
|
| 34 |
if ( current_user_can( apply_filters( 'trp_translating_capability', 'manage_options' ) ) && ! is_admin() ) {
|
| 35 |
return true;
|
|
|
|
|
|
|
| 36 |
}else{
|
| 37 |
wp_die(
|
| 38 |
'<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
|
|
@@ -547,6 +549,13 @@ class TRP_Translation_Manager{
|
|
| 547 |
$_REQUEST['trp-edit-translation'] = 'preview';
|
| 548 |
}
|
| 549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
global $TRP_LANGUAGE;
|
| 551 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 552 |
$url_converter = $trp->get_component( 'url_converter' );
|
|
@@ -852,4 +861,37 @@ class TRP_Translation_Manager{
|
|
| 852 |
return $classes;
|
| 853 |
}
|
| 854 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 855 |
}
|
| 33 |
if ( isset( $_REQUEST['trp-edit-translation'] ) && esc_attr( $_REQUEST['trp-edit-translation'] ) == $mode ) {
|
| 34 |
if ( current_user_can( apply_filters( 'trp_translating_capability', 'manage_options' ) ) && ! is_admin() ) {
|
| 35 |
return true;
|
| 36 |
+
}elseif ( esc_attr( $_REQUEST['trp-edit-translation'] ) == "preview" ){
|
| 37 |
+
return true;
|
| 38 |
}else{
|
| 39 |
wp_die(
|
| 40 |
'<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
|
| 549 |
$_REQUEST['trp-edit-translation'] = 'preview';
|
| 550 |
}
|
| 551 |
|
| 552 |
+
if( strpos( $referer, 'trp-edit-translation=preview' ) !== false && strpos( $referer, 'trp-view-as=' ) !== false && strpos( $referer, 'trp-view-as-nonce=' ) !== false ) {
|
| 553 |
+
$parts = parse_url($referer);
|
| 554 |
+
parse_str($parts['query'], $query);
|
| 555 |
+
$_REQUEST['trp-view-as'] = $query['trp-view-as'];
|
| 556 |
+
$_REQUEST['trp-view-as-nonce'] = $query['trp-view-as-nonce'];
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
global $TRP_LANGUAGE;
|
| 560 |
$trp = TRP_Translate_Press::get_trp_instance();
|
| 561 |
$url_converter = $trp->get_component( 'url_converter' );
|
| 861 |
return $classes;
|
| 862 |
}
|
| 863 |
|
| 864 |
+
|
| 865 |
+
public function trp_view_as_user(){
|
| 866 |
+
if( !is_admin() || $this::is_ajax_on_frontend() ) {
|
| 867 |
+
if (isset($_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] === 'preview' && isset($_REQUEST['trp-view-as']) && isset($_REQUEST['trp-view-as-nonce'])) {
|
| 868 |
+
|
| 869 |
+
if( apply_filters( 'trp_allow_translator_role_to_view_page_as_other_roles', true ) ){
|
| 870 |
+
$current_user_can_change_roles = current_user_can( apply_filters( 'trp_translating_capability', 'manage_options' ) ) || current_user_can( 'manage_options' );
|
| 871 |
+
}
|
| 872 |
+
else{
|
| 873 |
+
$current_user_can_change_roles = current_user_can( 'manage_options' );
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
if ( $current_user_can_change_roles ) {
|
| 877 |
+
if ( ! wp_verify_nonce( $_REQUEST['trp-view-as-nonce'], 'trp_view_as'. sanitize_text_field( $_REQUEST['trp-view-as'] ) . get_current_user_id() ) ) {
|
| 878 |
+
wp_die( __( 'Security check', 'translatepress-multilingual' ) );
|
| 879 |
+
} else {
|
| 880 |
+
global $current_user;
|
| 881 |
+
$view_as = sanitize_text_field( $_REQUEST['trp-view-as'] );
|
| 882 |
+
if( $view_as === 'current_user' ){
|
| 883 |
+
return;
|
| 884 |
+
}
|
| 885 |
+
elseif ( $view_as === 'logged_out' ){
|
| 886 |
+
$current_user = new WP_User(0, 'trp_logged_out');
|
| 887 |
+
}
|
| 888 |
+
else{
|
| 889 |
+
$current_user = apply_filters( 'trp_temporary_change_current_user_role', $current_user, $view_as );
|
| 890 |
+
}
|
| 891 |
+
}
|
| 892 |
+
}
|
| 893 |
+
}
|
| 894 |
+
}
|
| 895 |
+
}
|
| 896 |
+
|
| 897 |
}
|
includes/class-url-converter.php
CHANGED
|
@@ -112,29 +112,25 @@ class TRP_Url_Converter {
|
|
| 112 |
public function get_url_for_language ( $language = null, $url = null ) {
|
| 113 |
global $post, $TRP_LANGUAGE;
|
| 114 |
$trp_language_copy = $TRP_LANGUAGE;
|
| 115 |
-
|
| 116 |
if ( empty( $language ) ) {
|
| 117 |
$language = $TRP_LANGUAGE;
|
| 118 |
}
|
| 119 |
$url_slug = $this->get_url_slug( $language );
|
| 120 |
if ( empty( $url ) && is_object( $post ) && is_singular() ) {
|
|
|
|
| 121 |
$TRP_LANGUAGE = $language;
|
| 122 |
$new_url = get_permalink( $post->ID );
|
| 123 |
$TRP_LANGUAGE = $trp_language_copy;
|
| 124 |
}else{
|
|
|
|
| 125 |
if ( empty( $url ) ) {
|
| 126 |
-
$url = $this->cur_page_url();
|
| 127 |
}
|
| 128 |
$abs_home = trailingslashit( $this->get_abs_home() );
|
| 129 |
-
$
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
$path = substr($url, strlen($prefix));
|
| 133 |
-
$path = ltrim($path, '/');
|
| 134 |
-
$new_url = trailingslashit( $abs_home . $url_slug ) . $path;
|
| 135 |
-
break;
|
| 136 |
-
}
|
| 137 |
-
}
|
| 138 |
}
|
| 139 |
|
| 140 |
/* fix links for woocommerce on language switcher for product categories and product tags */
|
| 112 |
public function get_url_for_language ( $language = null, $url = null ) {
|
| 113 |
global $post, $TRP_LANGUAGE;
|
| 114 |
$trp_language_copy = $TRP_LANGUAGE;
|
| 115 |
+
|
| 116 |
if ( empty( $language ) ) {
|
| 117 |
$language = $TRP_LANGUAGE;
|
| 118 |
}
|
| 119 |
$url_slug = $this->get_url_slug( $language );
|
| 120 |
if ( empty( $url ) && is_object( $post ) && is_singular() ) {
|
| 121 |
+
// if we have a $post we need to run the language switcher through get_permalink so we apply the correct slug that can be different.
|
| 122 |
$TRP_LANGUAGE = $language;
|
| 123 |
$new_url = get_permalink( $post->ID );
|
| 124 |
$TRP_LANGUAGE = $trp_language_copy;
|
| 125 |
}else{
|
| 126 |
+
// If no $post is set we simply replace the current language root with the new language root.
|
| 127 |
if ( empty( $url ) ) {
|
| 128 |
+
$url = trailingslashit($this->cur_page_url());
|
| 129 |
}
|
| 130 |
$abs_home = trailingslashit( $this->get_abs_home() );
|
| 131 |
+
$current_language_root = trailingslashit($abs_home . $this->get_url_slug( $TRP_LANGUAGE ));
|
| 132 |
+
$new_language_root = trailingslashit($abs_home . $url_slug);
|
| 133 |
+
$new_url = trailingslashit( str_replace($current_language_root, $new_language_root, $url) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
}
|
| 135 |
|
| 136 |
/* fix links for woocommerce on language switcher for product categories and product tags */
|
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
|
| 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.0
|
| 7 |
Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
|
| 8 |
Author URI: https://cozmoslabs.com/
|
| 9 |
License: GPL2
|
partials/main-settings-language-selector.php
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<tr>
|
| 2 |
+
<th scope="row"> <?php _e( 'All Languages', 'translatepress-multilingual' ) ?> </th>
|
| 3 |
+
<td>
|
| 4 |
+
<table id="trp-languages-table">
|
| 5 |
+
<thead>
|
| 6 |
+
<tr>
|
| 7 |
+
<th colspan="2"><?php _e( 'Language', 'translatepress-multilingual' ); ?></th>
|
| 8 |
+
<th><?php _e( 'Slug', 'translatepress-multilingual' ); ?></th>
|
| 9 |
+
</tr>
|
| 10 |
+
</thead>
|
| 11 |
+
<tbody id="trp-sortable-languages">
|
| 12 |
+
|
| 13 |
+
<?php
|
| 14 |
+
|
| 15 |
+
// we should always have at least two languages in free version.
|
| 16 |
+
// edge case when enable multiple language addon, delete all languages and then disable multiple language addon. The free version won't be able to have two languages.
|
| 17 |
+
if( count($this->settings['translation-languages']) < 2 )
|
| 18 |
+
$this->settings['translation-languages'][] = '';
|
| 19 |
+
|
| 20 |
+
// we should force only two languages in the free version
|
| 21 |
+
$translation_languages = array();
|
| 22 |
+
foreach ($this->settings['translation-languages'] as $lang ){
|
| 23 |
+
if ( ( count($translation_languages) == 0 ) && ( $lang != $this->settings['default-language'] ) ){
|
| 24 |
+
$translation_languages[] = $lang;
|
| 25 |
+
} elseif( $lang == $this->settings['default-language']) {
|
| 26 |
+
$translation_languages[] = $lang;
|
| 27 |
+
} elseif( in_array($this->settings['default-language'], $translation_languages ) && count($translation_languages) == 1 ){
|
| 28 |
+
$translation_languages[] = $lang;
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
foreach ($translation_languages as $selected_language_code ){
|
| 33 |
+
$default_language = ( $selected_language_code == $this->settings['default-language'] );?>
|
| 34 |
+
<tr class="trp-language">
|
| 35 |
+
<td><span class="trp-sortable-handle"></span></td>
|
| 36 |
+
<td>
|
| 37 |
+
<select name="trp_settings[translation-languages][]" class="trp-select2 trp-translation-language" <?php echo ( $default_language ) ? 'disabled' : '' ?>>
|
| 38 |
+
<option value=""><?php _e( 'Choose...', 'translatepress-multilingual' );?></option>
|
| 39 |
+
<?php foreach( $languages as $language_code => $language_name ){ ?>
|
| 40 |
+
<option title="<?php echo $language_code; ?>" value="<?php echo $language_code; ?>" <?php echo ( $language_code == $selected_language_code ) ? 'selected' : ''; ?>>
|
| 41 |
+
<?php echo ( $default_language ) ? 'Default: ' : ''; ?>
|
| 42 |
+
<?php echo $language_name; ?>
|
| 43 |
+
</option>
|
| 44 |
+
<?php }?>
|
| 45 |
+
</select>
|
| 46 |
+
<input type="hidden" class="trp-translation-published" name="trp_settings[publish-languages][]" value="<?php echo $selected_language_code;?>" />
|
| 47 |
+
<?php if ( $default_language ) { ?>
|
| 48 |
+
<input type="hidden" class="trp-hidden-default-language" name="trp_settings[translation-languages][]" value="<?php echo $selected_language_code;?>" />
|
| 49 |
+
<?php } ?>
|
| 50 |
+
</td>
|
| 51 |
+
<td>
|
| 52 |
+
<input class="trp-language-slug" name="trp_settings[url-slugs][<?php echo $selected_language_code ?>]" type="text" style="text-transform: lowercase;" value="<?php echo $this->url_converter->get_url_slug( $selected_language_code, false ); ?>">
|
| 53 |
+
</td>
|
| 54 |
+
</tr>
|
| 55 |
+
<?php }?>
|
| 56 |
+
</tbody>
|
| 57 |
+
</table>
|
| 58 |
+
<div id="trp-new-language">
|
| 59 |
+
<select id="trp-select-language" class="trp-select2 trp-translation-language" >
|
| 60 |
+
<option value=""><?php _e( 'Choose...', 'translatepress-multilingual' );?></option>
|
| 61 |
+
<?php foreach( $languages as $language_code => $language_name ){ ?>
|
| 62 |
+
<option title="<?php echo $language_code; ?>" value="<?php echo $language_code; ?>">
|
| 63 |
+
<?php echo $language_name; ?>
|
| 64 |
+
</option>
|
| 65 |
+
<?php }?>
|
| 66 |
+
</select>
|
| 67 |
+
<button type="button" id="trp-add-language" class="button-secondary"><?php _e( 'Add', 'translatepress-multilingual' );?></button>
|
| 68 |
+
</div>
|
| 69 |
+
<p class="description">
|
| 70 |
+
<?php
|
| 71 |
+
_e( 'Select the language you wish to make your website available in.', 'translatepress-multilingual');
|
| 72 |
+
?>
|
| 73 |
+
</p>
|
| 74 |
+
<p class="trp-upsell-multiple-languages" style="display: none;">
|
| 75 |
+
<?php
|
| 76 |
+
$url = trp_add_affiliate_id_to_link('https://translatepress.com/?utm_source=wpbackend&utm_medium=clientsite&utm_content=multiple_languages&utm_campaign=tpfree');
|
| 77 |
+
$link = sprintf( wp_kses( __( 'To add <strong>more then two languages</strong> and support for SEO Title, Description, Slug and more checkout <a href="%s" class="button button-primary" target="_blank" title="TranslatePress Pro">TranslatePress PRO</a>', 'translatepress-multilingual' ), array( 'strong' => array(), 'br' => array(), 'a' => array( 'href' => array(), 'title' => array(), 'target'=> array(), 'class' => array() ) ) ), esc_url( $url ) );
|
| 78 |
+
$link .= '<br/>' . __('Not only you are getting extra features and premium support, you also help fund the future development of TranslatePress.', 'translatepress-multilingual');
|
| 79 |
+
echo $link;
|
| 80 |
+
?>
|
| 81 |
+
</p>
|
| 82 |
+
</td>
|
| 83 |
+
</tr>
|
partials/translation-manager.php
CHANGED
|
@@ -73,6 +73,26 @@
|
|
| 73 |
<button type="button" id="trp-next" class="trp-next-previous-buttons"><?php _e( 'Next', 'translatepress-multilingual' ); ?> <span>»</span></button>
|
| 74 |
</div>
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
</div>
|
| 77 |
<br class="clear">
|
| 78 |
|
| 73 |
<button type="button" id="trp-next" class="trp-next-previous-buttons"><?php _e( 'Next', 'translatepress-multilingual' ); ?> <span>»</span></button>
|
| 74 |
</div>
|
| 75 |
|
| 76 |
+
<div id="trp-view-as">
|
| 77 |
+
<div id="trp-view-as-description"><?php _e( 'View as', 'translatepress-multilingual' ); ?></div>
|
| 78 |
+
<select id="trp-view-as-select" onchange='trpEditor.change_view_as( this )'>
|
| 79 |
+
<?php
|
| 80 |
+
$trp_view_as_values = array( __('Current User', 'translatepress-multilingual') => 'current_user', __('Logged Out', 'translatepress-multilingual') => 'logged_out' );
|
| 81 |
+
$trp_all_roles = wp_roles()->roles;
|
| 82 |
+
if( !empty( $trp_all_roles ) ){
|
| 83 |
+
foreach( $trp_all_roles as $trp_all_role ){
|
| 84 |
+
$trp_view_as_values[$trp_all_role['name']] = '';
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
$trp_view_as_values = apply_filters( 'trp_view_as_values', $trp_view_as_values );
|
| 88 |
+
|
| 89 |
+
?>
|
| 90 |
+
<?php foreach ( $trp_view_as_values as $trp_view_as_label => $trp_view_as_value ) { ?>
|
| 91 |
+
<option value="<?php echo $trp_view_as_value; ?>" <?php if( empty( $trp_view_as_value ) ){ echo 'disabled="disabled" title="'. __( 'Available in our Pro Versions', 'translatepress-multilingual' ) .'"'; }?> data-view-as-nonce="<?php echo wp_create_nonce( 'trp_view_as'.$trp_view_as_value.get_current_user_id() ); ?>" <?php if( isset($_REQUEST['trp-view-as']) ){ echo ( sanitize_text_field( $_REQUEST['trp-view-as'] ) == $trp_view_as_value ) ? 'selected' : ''; } ?>> <?php echo $trp_view_as_label; ?> </option>
|
| 92 |
+
<?php } ?>
|
| 93 |
+
</select>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
</div>
|
| 97 |
<br class="clear">
|
| 98 |
|
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.0
|
| 7 |
-
Stable tag: 1.0
|
| 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.0.9 =
|
| 111 |
* We now flush permalinks when saving the settings page to avoid getting 404 and 500 errors
|
| 112 |
* Added the current language as a class on the body tag. Ex: translatepress-en_US
|
| 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.0
|
| 7 |
+
Stable tag: 1.1.0
|
| 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.0 =
|
| 111 |
+
* Implemented View As "Logged out user" functionality so you can translate strings that show only for logged out users
|
| 112 |
+
* Allow slug edit for default language
|
| 113 |
+
* Fixed an issue with the dropdown of translation strings when there were unsaved changes and the dropdown disconected from the textarea
|
| 114 |
+
* Prevent translate editor icon pencil to exit the translation iframe
|
| 115 |
+
* Fixed translating via the next/prev buttons that reset the position in the translation string list
|
| 116 |
+
* Refactor the way we are generating the language url for the language switcher when we don't have a variable available
|
| 117 |
+
|
| 118 |
= 1.0.9 =
|
| 119 |
* We now flush permalinks when saving the settings page to avoid getting 404 and 500 errors
|
| 120 |
* Added the current language as a class on the body tag. Ex: translatepress-en_US
|
