Plugin Directory

Changeset 3255173


Ignore:
Timestamp:
03/13/2025 07:38:31 AM (2 weeks ago)
Author:
mvpis
Message:

Update with enhancements

Location:
fluentc-translation/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fluentc-translation/trunk/fluentc_wordpress_plugin.php

    r3253696 r3255173  
    77 * Plugin URI: https://www.fluentc.ai
    88 * Description: A plugin that enables website owners to easily install the FluentC Translation on their WordPress site.
    9  * Version: 2.4.3
     9 * Version: 2.4.4
    1010 * Author: FluentC
    1111 * Author URI: https://www.fluentc.ai
     
    1717define( 'FLUENTC_DIR', __DIR__ );
    1818define( 'FLUENTC_SLUG', 'fluentc_translation' );
    19 define( 'FLUENTC_TRANSLATION_VERSION', "2.4.3" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "2.4.4" );
    2020define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_URL', plugin_dir_url(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3253696 r3255173  
    55Requires at least: 4.6
    66Tested up to: 6.6.2
    7 Stable tag: 2.4.3
     7Stable tag: 2.4.4
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/actions/class-wordpress.php

    r3253696 r3255173  
    169169        add_action('fluentc_language_set', array($this, 'refresh_language_code'));
    170170       
    171         // Register browser language detection and redirection.
    172         add_action('template_redirect', array($this, 'fluentc_language_redirect'), 1);
     171   
    173172    }
    174173   
     
    454453    }
    455454
    456     /**
    457      * Get translation manager, initializing if needed
    458      *
    459      * @return Translation_Manager|null
    460      */
    461     private function get_translation_manager() {
    462         // Don't translate if no language code
    463         if (!$this->language_code) {
    464             return null;
    465         }
    466        
    467         // Skip translation if current language is same as site language
    468         if ($this->language_code === $this->site_language) {
    469             return null;
    470         }
    471        
    472         // Initialize translation manager if not already done
    473         if ($this->translation_manager === null) {
    474             try {
    475                 $this->translation_manager = new Translation_Manager(
    476                     $this->fluentc_connect,
    477                     $this->fluentc_cache,
    478                     $this->site_language,
    479                     $this->language_code
    480                 );
    481             } catch (\Exception $e) {
    482                 error_log('FluentC: Error initializing Translation Manager: ' . $e->getMessage());
    483                 return null;
    484             }
    485         }
    486        
    487         return $this->translation_manager;
    488     }
    489 
    490     /**
    491      * Redirect users based on browser language
    492      *
    493      * @return void
    494      */
    495     public function fluentc_language_redirect() {
    496         // Skip if already on a language page or in admin/AJAX context
    497         if ($this->language_code || is_admin() || wp_doing_ajax()) {
    498             return;
    499         }
    500        
    501         // Get API key
    502         $widgetapikey = $this->widgetapikey;
    503         if (!$widgetapikey) {
    504             return;
    505         }
    506        
    507         // Get default language
    508         $default_language = $this->fluentc_language->fluentc_site_language();
    509        
    510         // Get browser language
    511         $user_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : '';
    512         if (empty($user_language)) {
    513             return;
    514         }
    515    
    516         // Get available languages
    517         $available_languages = $this->fluentc_connect->get_display_language_list($widgetapikey);
    518         if (empty($available_languages)) {
    519             return;
    520         }
    521    
    522         // Find matching language
    523         $matching_language = null;
    524         foreach ($available_languages as $language) {
    525             if (strtolower($language[1]) === strtolower($user_language)) {
    526                 $matching_language = $language[1];
    527                 break;
    528             }
    529         }
    530    
    531         // FIXED: Only redirect if matching language is NOT the default language
    532         if ($matching_language && strtolower($matching_language) !== strtolower($default_language)) {
    533             // Get current URL
    534             $current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") .
    535                 "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    536    
    537             // Use helper function if available
    538             if (function_exists('fluentc_add_language_to_url')) {
    539                 $new_url = fluentc_add_language_to_url($current_url, $matching_language);
    540                 wp_redirect($new_url);
    541                 exit;
    542             }
    543            
    544             // Legacy approach if helper function not available
    545             $url_parts = wp_parse_url($current_url);
    546            
    547             // Check if language code already in URL
    548             if (!isset($url_parts['path']) || !preg_match('/\/' . $matching_language . '(\/|$|\?|#)/', $url_parts['path'])) {
    549                 // Add language code to path
    550                 $new_path = '/' . $matching_language . (isset($url_parts['path']) ? $url_parts['path'] : '/');
    551                
    552                 // Rebuild URL with language code
    553                 $new_url = $url_parts['scheme'] . '://' . $url_parts['host'] . $new_path;
    554                
    555                 if (!empty($url_parts['query'])) {
    556                     $new_url .= '?' . $url_parts['query'];
    557                 }
    558                
    559                 if (!empty($url_parts['fragment'])) {
    560                     $new_url .= '#' . $url_parts['fragment'];
    561                 }
    562                
    563                 wp_redirect($new_url);
    564                 exit;
    565             }
    566         }
    567     }
     455   
    568456}
  • fluentc-translation/trunk/src/fluentc_language_functions.php

    r3249935 r3255173  
    117117    }
    118118   
     119    // Get the default language
     120    $default_language = fluentc_get_default_language();
     121   
     122    // Don't add language code if it's the default language
     123    if ($language_code === $default_language) {
     124        return $url;
     125    }
     126   
    119127    $url_parts = parse_url($url);
    120128   
Note: See TracChangeset for help on using the changeset viewer.