Plugin Directory

Changeset 3174633


Ignore:
Timestamp:
10/23/2024 09:41:01 PM (18 months ago)
Author:
mvpis
Message:

Updates

Location:
fluentc-translation
Files:
370 added
11 edited

Legend:

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

    r3170433 r3174633  
    4343            '\FluentC\Services\Cache',
    4444            '\FluentC\Services\Url',
    45             '\FluentC\Services\Frontpage',
    4645            '\FluentC\Services\Widget',
    4746            '\FluentC\Services\Connect',
  • fluentc-translation/trunk/fluentc_wordpress_plugin.php

    r3172365 r3174633  
    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.0.3
     9 * Version: 2.0.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.0.3" );
     19define( 'FLUENTC_TRANSLATION_VERSION', "2.0.4" );
    2020define( 'FLUENTC_TRANSLATION_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    2121define( 'FLUENTC_TRANSLATION_PLUGIN_URL', plugin_dir_url(__FILE__) );
  • fluentc-translation/trunk/readme.txt

    r3172365 r3174633  
    55Requires at least: 4.6
    66Tested up to: 6.6.2
    7 Stable tag: 2.0.3
     7Stable tag: 2.0.4
    88Requires PHP: 7.3
    99License: GPLv2 or later
  • fluentc-translation/trunk/src/actions/class-admin.php

    r3161147 r3174633  
    429429    {
    430430        $widgetapikey = get_option('fluentc_api_key');
     431        if(!$widgetapikey){
     432            return;
     433        }
    431434        $languages = $this->fluentc_connect->get_display_language_list($widgetapikey);
    432435
  • fluentc-translation/trunk/src/actions/class-insert.php

    r3162981 r3174633  
    107107
    108108        $widgetapikey = get_option( 'fluentc_api_key' );
     109        if(!$widgetapikey){
     110            return;
     111        }
    109112        $widget       = $this->fluentc_connect->fetch_widget_options( $widgetapikey );
     113        if(!$widget  ){
     114            return;
     115        }
    110116        $apperance    = $widget->data->fetchSiteOptions->appearance;
    111117        if ( ! $apperance ) {
  • fluentc-translation/trunk/src/actions/class-wordpress.php

    r3170433 r3174633  
    128128     */
    129129    public function hooks() {
    130         /* add_filter( 'the_title', array( $this, 'fluentcFilterTitle' ), 9999, 2 );
    131         add_filter( 'the_content', array( $this, 'filter_content' ), 9999, 1 );
    132         add_filter( 'widget_text', array( $this, 'fluentcFilterWidgetText' ), 9999, 2 );
    133         add_filter( 'widget_block_content', array( $this, 'fluentcFilterWidgetText' ), 999, 2 );
    134         add_filter( 'render_block', array( $this, 'filter_block' ), 9999, 2 );
    135         add_filter( 'wp_nav_menu', array( $this, 'fluentcFilterWidgetText' ), 100, 2 );
    136         add_filter( 'do_shortcode_tag', array( $this, 'fluentc_woocommerce_checkout_shortcode_filter' ), 100, 3 );
    137         add_filter( 'woocommerce_archive_description', array( $this, 'filter_content' ), 100, 1 );
    138         add_filter( 'woocommerce_product_title', array( $this, 'fluentcFilterTitle' ), 100, 2 );
    139         add_filter( 'woocommerce_my_account_shortcode_content', array( $this, 'filter_content' ), 100, 1 );
    140         add_filter( 'woocommerce_product_shortcode_content', array( $this, 'filter_content' ), 100, 1 );
    141         add_filter( 'woocommerce_short_description', array( $this, 'filter_content' ), 100, 1 );
    142         add_filter( 'woocommerce_get_script_data', array( $this, 'ffluentc_woo_script_data' ), 100, 1 );
    143         add_filter( 'shutdown', array( $this, 'fluentc_shutdown' ), 100, 1 );
    144        */
    145         add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'correct_multilingual_ajax_endpoint' ), 100, 2 );
     130        add_filter( 'woocommerce_ajax_get_endpoint', array( $this, 'correct_multilingual_ajax_endpoint' ), 100, 2 );
    146131        add_action('init', [$this, 'init_output_buffering'], 0);
    147132        add_action('shutdown', [$this, 'fluentc_flush_output_buffer'], 0);
     
    193178     // Don't process JSON responses.
    194179     if ($this->is_json($buffer)) {
    195         return $buffer;
     180        $processed_json = $this->process_json($buffer);
     181        return $processed_json;
    196182    }
    197183
     
    243229    }
    244230
    245 
    246 
    247      /**
    248      * Filters Blocks
    249      *
    250      * @param  string $block_content Content of a Block.
    251      * @param  string $block Block Object.
    252      */
    253     public function filter_block($block_content, $block)
    254     {
    255         if (!$this->should_process_content($block_content)) {
    256             return $block_content;
    257         }
    258 
    259         $translation_manager = $this->get_translation_manager();
    260         if ($translation_manager === null) {
    261             return $block_content; // No translation needed
    262         }
    263        
    264         $html = $this->htmlProcessor->processHtml(
    265             $block_content,
    266             $this->site_language,
    267             $this->language_code,
    268         );
    269        
    270         // Remove the translated flag before returning
    271         return $html ?: $block_content;
    272     }
    273231    /**
    274      * Filter title
    275      */
    276     public function fluentcFilterTitle($title, $id = null)
    277     {
    278         if (!$this->language_code) {
    279             return $title;
    280         }
    281         $translation_manager = $this->get_translation_manager();
    282         if ($translation_manager === null) {
    283             return $title; // No translation needed
    284         }
    285        
    286     $html = $this->htmlProcessor->processHtml(
    287         $title,
    288         $this->site_language,
    289         $this->language_code
    290      
    291     );
     232     * Summary of process_json  which is used to support HTML that is returned in JSON.
     233     * @param mixed $json_string
     234     * @return mixed
     235     */
     236    public function process_json($json_string) {
     237        // Decode the JSON string
     238       
     239        $data = json_decode($json_string, true);
    292240   
    293     return $html ?: $title;
     241       if (!is_array($data)) {
     242        return $json_string; // Return original JSON if it's not a valid JSON object
     243       }
     244   
     245        // Process each facet
     246        if (isset($data['facets']) && is_array($data['facets'])) {
     247        foreach ($data['facets'] as $key => &$facet) {
     248            if (isset($facet['html'])) {
     249                $processed_html = $this->filter_content($facet['html']);
     250                $facet['html'] = $processed_html;
     251            }
     252   
     253            // Process name if it exists
     254            if (isset($facet['name'])) {
     255                 $facet['name'] = $this->filter_content($facet['name']);
     256            }
     257        }
     258    }
     259    if (isset($data['posts']) && is_string($data['posts'])) {
     260        $processed_html = $this->filter_content($data['posts']);
     261        $data['posts'] = $processed_html;
     262    }
     263     if (isset($data['content']) && is_string($data['content'])) {
     264        $processed_html = $this->filter_content($data['content']);
     265        $data['content'] = $processed_html;
     266    }
     267        // Encode the updated data back to JSON
     268        return json_encode($data);
    294269    }
    295270
     
    322297
    323298
    324     /**
    325      * Updates Home page link
    326      *
    327      * @param  string $text Text Content.
    328      * @param  string $instance Instance details of the widget.
    329      */
    330     public function fluentcFilterWidgetText($text, $instance)
    331     {
    332         if (!$this->should_process_content($text)) {
    333             return $text;
    334         }
    335 
    336         $html = $this->htmlProcessor->processHtml(
    337             $text,
    338             $this->site_language,
    339             $this->language_code
    340         );
    341        
    342         return $html ?: $text;
    343     }
    344    
    345299
    346300    /**
  • fluentc-translation/trunk/src/models/class-htmltags.php

    r3170433 r3174633  
    177177    }
    178178
     179    /**
     180     * Summary of processLink
     181     * @param string $url
     182     * @param string $language_code
     183     * @return string
     184     */
    179185    public function processLink(string $url, string $language_code): string {
    180186        $parsed_url = parse_url($url);
     
    194200    }
    195201
     202    /**
     203     * Summary of shouldSkipProcessing
     204     * @param mixed $url
     205     * @param mixed $parsed_url
     206     * @param mixed $is_relative_path
     207     * @return bool
     208     */
    196209    private function shouldSkipProcessing($url, $parsed_url, $is_relative_path): bool {
    197210        return $is_relative_path ||
     
    201214    }
    202215
     216    /**
     217     * Summary of hasLanguageCode
     218     * @param mixed $path
     219     * @param mixed $language_code
     220     * @return bool
     221     */
    203222    private function hasLanguageCode($path, $language_code): bool {
    204223        $path_segments = explode('/', trim($path, '/'));
     
    206225    }
    207226
     227    /**
     228     * Summary of addLanguageCodeToLink
     229     * @param mixed $language_code
     230     * @param mixed $url
     231     * @return string
     232     */
    208233    private function addLanguageCodeToLink($language_code, $url) {
    209234        $url_parts = wp_parse_url($url);
     
    269294        return $new_permalink;
    270295    }
    271 
    272     /*public function processLink(string $url, string $language_code): string
    273     {
    274         //$current_language_code = $this->getLanguageFromUrl($url, $regex_lang);
    275         $parsed_url = parse_url($url);
    276         $is_relative_path = empty($parsed_url['host']);
    277         $root_url = home_url();
    278        
    279         if (
    280             $is_relative_path ||
    281             (isset($parsed_url['host']) && parse_url($root_url, PHP_URL_HOST) !== $parsed_url['host']) ||
    282             strpos($url, '/wp-admin/') !== false ||
    283             $this->check_for_file($url)) {
    284             return $url;
    285         }
    286 
    287         return $this->add_language_code_to_link($language_code, $url);
    288     } */
    289 
     296   
    290297    private function getLanguageFromUrl($url, $regex_lang) {
    291298        $pattern = '/\/(' . $regex_lang . ')(\/|$|\?|#)/';
  • fluentc-translation/trunk/src/services/class-cache.php

    r3171783 r3174633  
    383383        return $translations;
    384384    }
    385    
     385    /**
     386     * Summary of count_search_results
     387     * @param mixed $search_term
     388     * @return mixed
     389     */
    386390    public function count_search_results($search_term) {
    387391        global $wpdb;
  • fluentc-translation/trunk/src/services/class-connect.php

    r3171783 r3174633  
    2626class Connect
    2727{
     28    /**
     29     * Summary of fluentc_cache
     30     * @var
     31     */
    2832    protected $fluentc_cache;
     33    /**
     34     * Summary of fluentc_remote_url
     35     * @var
     36     */
    2937    protected $fluentc_remote_url;
     38    /**
     39     * Summary of api_key
     40     * @var string
     41     */
    3042    protected $api_key = 'da2-wtkl5bpofjbu5ex5iugu4o2mbm';
    31 
     43    /**
     44     * Summary of __construct
     45     */
    3246    public function __construct()
    3347    {
     
    3549        $this->fluentc_remote_url = 'https://dashboard.fluentc.ai/graphql';
    3650    }
    37 
     51    /**
     52     * Summary of get_language_list
     53     * @param mixed $widget_id
     54     * @return mixed
     55     */
    3856    public function get_language_list($widget_id)
    3957    {
     
    4866        }, 43200);
    4967    }
    50 
     68    /**
     69     * Summary of get_display_language_list
     70     * @param mixed $widget_id
     71     * @return mixed
     72     */
    5173    public function get_display_language_list($widget_id)
    5274    {
     
    116138        return empty($args['fields']) ? $languages : wp_list_pluck($languages, $args['fields']);
    117139    }
    118 
     140    /**
     141     * Summary of fetch_widget_options
     142     * @param mixed $widget_id
     143     * @return mixed
     144     */
    119145    public function fetch_widget_options($widget_id)
    120146    {
     
    125151        }, 43200);
    126152    }
    127 
     153    /**
     154     * Summary of get_available_languages
     155     * @param mixed $environment_id
     156     * @return mixed
     157     */
    128158    public function get_available_languages($environment_id)
    129159    {
     
    132162        );
    133163    }
    134 
     164    /**
     165     * Summary of get_translation_text
     166     * @param mixed $widget_id
     167     * @param mixed $source_language
     168     * @param mixed $target_language
     169     * @param mixed $text
     170     * @param mixed $id
     171     * @return mixed
     172     */
    135173    public function get_translation_text($widget_id, $source_language, $target_language, $text, $id = null)
    136174    {
     
    209247        return $this->processTranslationWithPlaceholderResponse($response);
    210248    }
    211 
     249    /**
     250     * Summary of formatLabels
     251     * @param mixed $text_labels
     252     * @return string|null
     253     */
    212254    private function formatLabels($text_labels)
    213255    {
     
    225267
    226268 
    227 
     269    /**
     270     * Summary of buildTranslationQuery
     271     * @param mixed $widget_id
     272     * @param mixed $source_language
     273     * @param mixed $target_language
     274     * @param mixed $labels_string
     275     * @return string
     276     */
    228277    private function buildTranslationQuery($widget_id, $source_language, $target_language, $labels_string)
    229278    {
     
    246295        GRAPHQL;
    247296    }
    248 
     297    /**
     298     * Summary of convertTranslationArrayFormat
     299     * @param mixed $translationArray
     300     * @return string[][]
     301     */
    249302    private function convertTranslationArrayFormat($translationArray)
    250303    {
     
    260313        return $convertedArray;
    261314    }
     315    /**
     316     * Summary of buildTranslationQueryWithPlaceholders
     317     * @param mixed $widget_id
     318     * @param mixed $source_language
     319     * @param mixed $target_language
     320     * @param mixed $labels_array
     321     * @return string
     322     */
    262323    private function buildTranslationQueryWithPlaceholders($widget_id, $source_language, $target_language, $labels_array)
    263324    {
     
    289350        GRAPHQL;
    290351    }
    291 
     352    /**
     353     * Summary of processTranslationResponse
     354     * @param mixed $response
     355     * @return string[]
     356     */
    292357    private function processTranslationResponse($response)
    293358    {
     
    301366    }
    302367
     368    /**
     369     * Summary of processTranslationWithPlaceholderResponse
     370     * @param mixed $response
     371     * @return array<mixed|string>[]
     372     */
    303373    private function processTranslationWithPlaceholderResponse($response)
    304374{
     
    353423        return null;
    354424    }
    355 
     425    /**
     426     * Summary of getSiteUrl
     427     * @return string
     428     */
    356429    private function getSiteUrl()
    357430    {
     
    382455    return $data;
    383456}
    384 
     457/**
     458 * Summary of get_pll_fluentc_languages_list
     459 * @param mixed $args
     460 * @return array
     461 */
    385462public function get_pll_fluentc_languages_list($args = [])
    386463{
     
    411488}
    412489
     490/**
     491 * Summary of getPLLCachedOrFetch
     492 * @param mixed $key
     493 * @param mixed $fetchCallback
     494 * @param mixed $expiration
     495 * @return array
     496 */
    413497private function getPLLCachedOrFetch($key, $fetchCallback, $expiration = 0)
    414498{
     
    428512    return is_array($data) ? $data : [];
    429513}
    430 
     514    /**
     515     * Summary of makeGraphQLRequest
     516     * @param mixed $query
     517     * @return mixed
     518     */
    431519    private function makeGraphQLRequest($query)
    432520    {
     
    458546    }
    459547
     548    /**
     549     * Summary of handleRequestError
     550     * @param mixed $status
     551     * @param mixed $response_data
     552     * @return void
     553     */
    460554    private function handleRequestError($status, $response_data)
    461555    {
  • fluentc-translation/trunk/src/services/class-translation-manager.php

    r3172365 r3174633  
    2525        $this->targetLanguage = $targetLanguage;
    2626        $this->placeholder_manager = new Placeholder_Manager();
    27     }
    28 
    29 
    30     public function translate(string $text, string $sourceLanguage, string $targetLanguage): string {
    31         $cacheKey = $this->getCacheKey($text, $sourceLanguage, $targetLanguage);
    32         $cachedTranslation = $this->cache->get($cacheKey);
    33 
    34         if ($cachedTranslation !== false) {
    35             return $cachedTranslation;
    36         }
    37 
    38         $this->translationBatch[] = $text;
    39 
    40        
    41         $this->processBatch();
    42        
    43 
    44         return $text; // Return original text for now, it will be replaced in processBatch
    45     }
    46 
    47     private function processBatch(): void {
    48         $translations = $this->connect->get_translation_content(
    49             get_option('fluentc_api_key'),
    50             $this->sourceLanguage,
    51             $this->targetLanguage,
    52             $this->translationBatch
    53         );
    54 
    55         foreach ($translations as $originalText => $translatedText) {
    56             $cacheKey = $this->getCacheKey($originalText, $this->sourceLanguage, $this->targetLanguage);
    57             $this->cache->set($cacheKey, json_encode([
    58                 'data' => [
    59                     'translateSite' => [
    60                         'body' => [
    61                             [
    62                                 'sourceLanguage' => $this->sourceLanguage,
    63                                 'targetLanguage' => $this->targetLanguage,
    64                                 'originalText' => $originalText,
    65                                 'translatedText' => $translatedText
    66                             ]
    67                         ]
    68                     ]
    69                 ]
    70             ]));
    71         }
    72 
    73         $this->translationBatch = [];
    7427    }
    7528
  • fluentc-translation/trunk/src/services/class-widget.php

    r3170433 r3174633  
    7979
    8080        $widgetapikey  = get_option( 'fluentc_api_key' );
     81        if(!$widgetapikey){
     82            return;
     83        }
    8184        $languages     = $this->fluentc_connect->get_display_language_list( $widgetapikey );
     85        if(!$languages){
     86            return;
     87        }
    8288        $widget        = $this->fluentc_connect->fetch_widget_options( $widgetapikey );
     89        if(!$widget  ){
     90            return;
     91        }
     92        $widget->data->fetchSiteOptions->appearance;
    8393        $apperance     = $widget->data->fetchSiteOptions->appearance;
    8494        $site_language = $this->fluentc_language->fluentc_site_language();
Note: See TracChangeset for help on using the changeset viewer.