Plugin Directory

Changeset 3352529


Ignore:
Timestamp:
08/29/2025 10:15:33 AM (7 months ago)
Author:
autoglot
Message:

Improved translation of AJAX-generated content

Location:
autoglot
Files:
68 added
4 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • autoglot/trunk/autoglot.php

    r3352146 r3352529  
    44Plugin URI: https://autoglot.com/download/
    55Description: Fully automatic SEO-friendly plugin for multilingual WordPress translation. Translate your website and boost your traffic in minutes! No coding, no subscription, no recurring payments, no hurdles!
    6 Version: 2.7.6
     6Version: 2.7.7
    77Text Domain: autoglot
    88Author: Autoglot WordPress Team
     
    7878        private $flushed_buffer = false;
    7979       
    80         /** is it custom ajax/json request with fragments for woo? */
    81         public $json_custom_request = false;
    82        
    83         /** is it custom ajax/html request like woo? */
    84         public $html_custom_request = false;
     80        /** is it custom ajax request for woo? */
     81        public $custom_ajax_request = false;
    8582       
    8683        /** content_type of generated response */
     
    103100            $this->langURL = autoglot_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->homeURL);
    104101
    105             if (autoglot_utils::is_custom_json()) {//is custom ajax/json like woocommerce requests
     102            if (autoglot_utils::is_custom_ajax()) {//is custom ajax like woocommerce request
    106103                $this->langURL = autoglot_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->homeURL);
    107                 $this->json_custom_request = true;
    108             } elseif (autoglot_utils::is_custom_html()) {//is custom ajax/html like woocommerce requests
     104                $this->custom_ajax_request = true;
     105/*            } elseif (autoglot_utils::is_custom_json()) {//is custom ajax/json like woocommerce requests
    109106                $this->langURL = autoglot_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->homeURL);
    110                 $this->html_custom_request = true;
     107                $this->custom_ajax_request = true;*/
    111108            } elseif(wp_is_json_request()) {//not custom ajax/json but json, so check lang and try from referer
    112109                if(!strlen($this->langURL)) $this->langURL = autoglot_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->homeURL);
     
    703700            }
    704701           
    705             if($this->response_content_type == "json" && !$this->json_custom_request){//it's json, let's check if it contains [html] or other items like woo cart, return if not
     702            if($this->response_content_type == "json" && !$this->custom_ajax_request){//it's json, let's check if it contains [html] or other items like woo cart, return if not
    706703                if ($buffer[0] == '{') {
    707704                    $tryjson = json_decode($buffer);
     
    751748                        return json_encode($tryjson); // return translated json
    752749
    753 /*                        if (isset($tryjson->html) && strlen($tryjson->html)) {
    754                             $tryjson->html = $this->translate_json($tryjson->html);
    755                             //$tryjson->translated_by = "Autoglot";
    756                             return json_encode($tryjson); // return translated json
    757                         }*/
    758                     //$tryjson->not_translated_by = "Autoglot";
    759                     //return json_encode($tryjson); // return not translated json
    760750                    }
    761751                }
    762752                return $buffer;
    763753            }
    764            
    765             if($this->json_custom_request) {
     754
     755            if($this->response_content_type == "json" && $this->custom_ajax_request) {
    766756                if ($buffer[0] == '{') {
    767757                   
     
    775765                            }
    776766                        }
    777                         //file_put_contents(__DIR__."/debug".time().".txt", print_r($tryjson->fragments, true), FILE_APPEND);
    778                         /*if (isset($tryjson->fragments->{'.woocommerce-checkout-review-order-table'})) {
    779                             $tryjson->fragments->{'.woocommerce-checkout-review-order-table'} = $this->translate_json($tryjson->fragments->{'.woocommerce-checkout-review-order-table'});
    780                         }
    781                         if (isset($tryjson->fragments->{'.woocommerce-checkout-payment'})) {
    782                             $tryjson->fragments->{'.woocommerce-checkout-payment'} = $this->translate_json($tryjson->fragments->{'.woocommerce-checkout-payment'});
    783                         }
    784                         if (isset($tryjson->fragments->{'div.widget_shopping_cart_content'})) {
    785                             $tryjson->fragments->{'div.widget_shopping_cart_content'} = $this->translate_json($tryjson->fragments->{'div.widget_shopping_cart_content'});
    786                         }*/
    787767                       
    788768                        //file_put_contents(__DIR__."/debug".time().".txt", print_r($tryjson->fragments, true), FILE_APPEND);
     
    794774            }
    795775
    796             if((is_admin() && wp_doing_ajax() && $this->response_content_type == "html") || $this->html_custom_request) {//custom ajax+html
     776            if((is_admin() && wp_doing_ajax() && $this->response_content_type == "html") || ($this->response_content_type == "html" && $this->custom_ajax_request)) {//custom ajax+html
    797777                if ($buffer[0] != '{') {
    798778                    $buffer = $this->translate_json($buffer);           
     
    885865                        // Process the value using the appropriate callback
    886866                        $callback_name = $process_callbacks[$key];
    887                         if ($callback_name === 'translate_url') {
    888                             // translate_url needs language parameter
    889                             $tryjson[$key] = $this->$callback_name($value, $this->langURL);
     867                        if ($callback_name === 'update_url') {
     868                            // update_url needs a different approach
     869                            if($this->options->translate_urls) {
     870                                $tryjson[$key] = autoglot_utils::add_language_to_url($this->translate_url($tryjson[$key], $this->langURL), $this->homeURL, $this->langURL);
     871                            } else {
     872                                $tryjson[$key] = autoglot_utils::add_language_to_url($tryjson[$key], $this->homeURL, $this->langURL);
     873                            }
    890874                        } else {
    891875                            // Other callbacks like translate_json only need the value
     
    906890                        // Process the value using the appropriate callback
    907891                        $callback_name = $process_callbacks[$key];
    908                         if ($callback_name === 'translate_url') {
    909                             // translate_url needs language parameter
    910                             $tryjson->$key = $this->$callback_name($value, $this->langURL);
     892                        if ($callback_name === 'update_url') {
     893                            // update_url needs a different approach
     894                            if($this->options->translate_urls) {
     895                                $tryjson->$key = autoglot_utils::add_language_to_url($this->translate_url($tryjson->$key, $this->langURL), $this->homeURL, $this->langURL);
     896                            } else {
     897                                $tryjson->$key = autoglot_utils::add_language_to_url($tryjson->$key, $this->homeURL, $this->langURL);
     898                            }
    911899                        } else {
    912900                            // Other callbacks like translate_json only need the value
  • autoglot/trunk/readme.txt

    r3352146 r3352529  
    55Tested up to: 6.8.2
    66Requires PHP: 7.0
    7 Stable tag: 2.7.6
     7Stable tag: 2.7.7
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    308308== Upgrade Notice ==
    309309
    310 = 2.7.6 =
     310= 2.7.7 =
    311311Improved WooCommerce integration
    312312
     
    343343== Screenshots ==
    344344
    345 1. Copy your API key from your Autoglot Control Panel and enable translation
    346 2. Choose as many languages as you need for translation
    347 3. Add a widget with language selector
    348 4. Enjoy new visitors on your SEO optimized translated multilingual website
     3451. No coding required: simply find, install and activate Autoglot plugin.
     3462. Register in our Autoglot Control Panel - it's free, no credit card required!
     3473. Autoglot Control Panel is the place to track your balance and add new orders.
     3484. Complete Autoglot setup in 3 simple steps.
     3495. You can always change Autoglot settings later!
     3506. Choose any type of language switcher: widgets, shortcodes, or floating box! 
     3517. Choose as many languages as you need for translation.
     3528. You can also change flags for the top popular languages like English or Spanish.
     3539. Autoglot supports MTPE with our convenient Translation editor.
     35410. Feel free to change links, videos or images in each language. 
    349355
    350356== Changelog ==
     357
     358= 2.7.7 (29/08/2025) =
     359* Improved WooCommerce integration
     360* Small fixes in translation of AJAX-generated JSON files
     361* Removed outdated code
     362* Added new screenshots to plugin description
    351363
    352364= 2.7.6 (28/08/2025) =
  • autoglot/trunk/utils/autoglot_constants.php

    r3352146 r3352529  
    177177        'html' => 'translate_json',
    178178        'content' => 'translate_json',
    179         'url' => 'translate_url',
     179        'url' => 'update_url',
    180180    );
    181181       
     
    255255
    256256//Define for autoglot plugin version
    257 define('AUTOGLOT_PLUGIN_VER', '2.7.6');
     257define('AUTOGLOT_PLUGIN_VER', '2.7.7');
    258258
    259259//Define for autoglot plugin name
  • autoglot/trunk/utils/autoglot_dom.php

    r3348279 r3352529  
    893893        // Generate final output
    894894        $output = "";
    895         if($this->autoglot->json_custom_request || $this->autoglot->html_custom_request || wp_is_json_request() || $this->autoglot->response_content_type == "json" || (is_admin() && wp_doing_ajax())){
     895        if($this->autoglot->custom_ajax_request || wp_is_json_request() || $this->autoglot->response_content_type == "json" || (is_admin() && wp_doing_ajax())){
    896896            $body = $this->dom_translated->getElementsByTagName('body')->item(0);
    897897            if ($body) foreach ($body->childNodes as $child) {
  • autoglot/trunk/utils/autoglot_utils.php

    r3352146 r3352529  
    380380
    381381    /**
    382      * Is it custom ajax+json request with fragments for woo carts etc., that should be translated?
    383      */
    384     public static function is_custom_json(){
     382     * Is it custom ajax request with fragments for woo carts etc., that should be translated?
     383     */
     384    public static function is_custom_ajax(){
    385385       
    386386        if ((isset($_GET['wc-ajax'])) ||
     
    397397     * Is it custom ajax+html request that should be translated?
    398398     */
    399     public static function is_custom_html(){
     399    /*public static function is_custom_html(){
    400400       
    401401        if ((isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'update_shipping_method')) {
     
    403403        }
    404404        return false;
    405     }
     405    }*/
    406406
    407407    /**
Note: See TracChangeset for help on using the changeset viewer.