Plugin Directory

Changeset 3408258


Ignore:
Timestamp:
12/02/2025 04:33:41 PM (4 months ago)
Author:
conveythis
Message:

Enhanced Change Flag feature with broader functionality.

Location:
conveythis-translate/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • conveythis-translate/trunk/app/class/ConveyThis.php

    r3394560 r3408258  
    338338        }
    339339
     340
    340341        $exclusions = $incoming['exclusions'] ?? null;
    341342        $glossary = $incoming['glossary'] ?? null;
     
    361362                update_option($field, $value);
    362363            }
     364        }
     365
     366        if (!array_key_exists('style_change_language', $incoming)) {
     367            update_option('style_change_language', []);
     368        }
     369
     370        if (!array_key_exists('style_change_flag', $incoming)) {
     371            update_option('style_change_flag', []);
    363372        }
    364373
  • conveythis-translate/trunk/app/class/Variables.php

    r3394560 r3408258  
    321321
    322322    public $matchingLanguages = array(
    323         703 => array('language_id' => 703, 'title_en' => 'English', 'title' => 'English', 'code2' => 'en', 'code3' => 'eng', 'flag' => 'us', 'flag_ids' => [498, 497, 342]),
    324         768 => array('language_id' => 768, 'title_en' => 'Portuguese', 'title' => 'Português', 'code2' => 'pt', 'code3' => 'por', 'flag' => 'br', 'flag_ids' => [422, 318, 348]),
    325         777 => array('language_id' => 777, 'title_en' => 'Spanish', 'title' => 'Español', 'code2' => 'es', 'code3' => 'spa', 'flag' => 'es', 'flag_ids' => [336]),
     323        703 => array(
     324            'language_id' => 703,
     325            'title_en'   => 'English',
     326            'title'      => 'English',
     327            'code2'      => 'en',
     328            'code3'      => 'eng',
     329            'flag'       => 'us',
     330            'flag_ids'   => [498, 497, 342],
     331        ),
     332
     333        719 => array(
     334            'language_id' => 719,
     335            'title_en'    => 'Chinese (Simplified)',
     336            'title'       => '简体',
     337            'code2'       => 'zh',
     338            'code3'       => 'zho-sim',
     339            'flag'        => 'cn',
     340            'flag_ids'    => [347, 466, 415], // China, Singapore, Malaysia
     341        ),
     342
     343        796 => array(
     344            'language_id' => 796,
     345            'title_en'    => 'Chinese (Traditional)',
     346            'title'       => '繁體',
     347            'code2'       => 'zh-tw',
     348            'code3'       => 'zho-tra',
     349            'flag'        => 'tw',
     350            'flag_ids'    => [347, 482, 508], // China, Taiwan, Hong Kong
     351        ),
     352
     353        707 => array(
     354            'language_id' => 707,
     355            'title_en'    => 'Arabic',
     356            'title'       => 'العربية',
     357            'code2'       => 'ar',
     358            'code3'       => 'ara',
     359            'flag'        => 'sa',
     360            'flag_ids'    => [
     361                324, 390, 396, 401, 405, 441, 451, 461, 481, 496, 505,
     362                314, 345, 349, 359, 363, 408, 420, 428, 470, 476, 490,
     363            ],
     364        ),
     365
     366        768 => array(
     367            'language_id' => 768,
     368            'title_en'    => 'Portuguese',
     369            'title'       => 'Português',
     370            'code2'       => 'pt',
     371            'code3'       => 'por',
     372            'flag'        => 'br',
     373            'flag_ids'    => [336, 450],
     374        ),
     375
     376        777 => array(
     377            'language_id' => 777,
     378            'title_en'    => 'Spanish',
     379            'title'       => 'Español',
     380            'code2'       => 'es',
     381            'code3'       => 'spa',
     382            'flag'        => 'es',
     383            'flag_ids'    => [422, 318, 348, 474], //Mexico, Argentina, Colombia, Spain
     384        ),
     385        727 => array(
     386            'language_id' => 727,
     387            'title_en'    => 'French',
     388            'title'       => 'Français',
     389            'code2'       => 'fr',
     390            'code3'       => 'fre',
     391            'flag'        => 'fr',
     392            'flag_ids'    => [371, 342], // France, Canada
     393        ),
    326394    );
    327395
    328396    public $matchingLanguageToFlag = array(
     397        // English: US / GB / CA
    329398        703 => array(498, 497, 342),
     399
     400        // Chinese (Simplified): Mainland China, Singapore, Malaysia
     401        719 => array(347, 466, 415),
     402
     403        // Chinese (Traditional): Taiwan, Hong Kong
     404        796 => array(482, 508),
     405
     406        // Arabic: Middle East + North Africa
     407        707 => array(
     408            // Middle East
     409            324, // Bahrain (bh)
     410            390, // Iraq (iq)
     411            396, // Jordan (jo)
     412            401, // Kuwait (kw)
     413            405, // Lebanon (lb)
     414            441, // Oman (om)
     415            451, // Qatar (qa)
     416            461, // Saudi Arabia (sa)
     417            481, // Syria (sy)
     418            496, // United Arab Emirates (ae)
     419            505, // Yemen (ye)
     420
     421            // North Africa
     422            314, // Algeria (dz)
     423            345, // Chad (td)
     424            349, // Comoros (km)
     425            359, // Djibouti (dj)
     426            363, // Egypt (eg)
     427            408, // Libya (ly)
     428            420, // Mauritania (mr)
     429            428, // Morocco (ma)
     430            470, // Somalia (so)
     431            476, // Sudan (sd)
     432            490, // Tunisia (tn)
     433        ),
     434
     435        // Portuguese: Brazil, Portugal
    330436        768 => array(336, 450),
    331         777 => array(422, 318, 348, 474)
     437
     438        // Spanish: Mexico, Argentina, Colombia, Spain
     439        777 => array(422, 318, 348, 474),
     440        727 => array(371, 342),
    332441    );
    333442
  • conveythis-translate/trunk/app/views/page/widget-style.php

    r3328452 r3408258  
    7171                    <div class="col-md-6">
    7272                        <div class="ui fluid search selection dropdown change_language">
     73                            <input type="hidden" class="style_change_flag" name="style_change_flag[]" value="">
    7374                            <i class="dropdown icon"></i>
    74                             <div class="default text"><?php echo  esc_html(__( 'Select language', 'conveythis-translate' )); ?></div>
     75                            <div class="default text">
     76                                <?php echo esc_html(__( 'Select language', 'conveythis-translate' )); ?>
     77                            </div>
    7578                            <div class="menu">
    76 
    7779                                <?php foreach( $this->variables->matchingLanguages as $id => $language ): ?>
    78 
    79                                     <div class="item" data-value="<?php echo  esc_attr($id); ?>">
     80                                    <div class="item" data-value="<?php echo esc_attr($id); ?>">
    8081                                        <?php echo esc_html( $language['title_en'], 'conveythis-translate' ); ?>
    8182                                    </div>
    82 
    8383                                <?php endforeach; ?>
    84 
    8584                            </div>
    8685                        </div>
    8786                    </div>
     87
    8888                    <div class="col-md-6">
    8989                        <div class="ui fluid search selection dropdown change_flag">
     90                            <input type="hidden" class="style_change_flag" name="style_change_flag[]" value="">
    9091                            <i class="dropdown icon"></i>
    91                             <div class="default text"><?php echo  esc_html(__( 'Select Flag', 'conveythis-translate' )); ?></div>
     92                            <div class="default text">
     93                                <?php echo esc_html(__( 'Select Flag', 'conveythis-translate' )); ?>
     94                            </div>
    9295                            <div class="menu">
    93 
    9496                                <?php foreach( $this->variables->matchingFlags as $flag ): ?>
    95 
    96                                     <div class="item" data-value="<?php echo  esc_attr( $flag['code'] ); ?>">
    97                                         <div class="ui image" style="height: 28px; width: 30px; background-position: 50% 50%; background-size: contain; background-repeat: no-repeat; background-image: url('//cdn.conveythis.com/images/flags/svg/<?php echo  esc_attr($flag['code']); ?>.svg')"></div>
     97                                    <div class="item" data-value="<?php echo esc_attr( $flag['code'] ); ?>">
     98                                        <div class="ui image" style="height:28px;width:30px;background-position:50% 50%;background-size:contain;background-repeat:no-repeat;background-image:url('//cdn.conveythis.com/images/flags/svg/<?php echo esc_attr($flag['code']); ?>.svg')"></div>
    9899                                        <?php echo esc_html( $flag['title'], 'conveythis-translate' ); ?>
    99100                                    </div>
    100 
    101101                                <?php endforeach; ?>
    102 
    103102                            </div>
    104103                        </div>
  • conveythis-translate/trunk/app/widget/js/settings.js

    r3394560 r3408258  
    1313            $('.ui.dropdown').dropdown({
    1414                onChange: function () {
    15                     conveythisSettings.view();
     15                    if (typeof conveythisSettings !== 'undefined' && conveythisSettings.view) {
     16                        conveythisSettings.view();
     17                    }
    1618                }
    1719            });
     
    124126        prepareSettingsBeforeSave();
    125127
    126         const data = Object.fromEntries(new FormData(form[0]));
     128        //const data = Object.fromEntries(new FormData(form[0]));
     129
     130        const raw = form.serializeArray();
     131        const data = {};
     132
     133        raw.forEach(function (item) {
     134            const name = item.name;
     135            const value = item.value;
     136
     137            if (name.endsWith('[]')) {
     138                // style_change_flag[] -> style_change_flag
     139                const key = name.slice(0, -2);
     140                if (!Array.isArray(data[key])) {
     141                    data[key] = [];
     142                }
     143                data[key].push(value);
     144            } else {
     145                if (!(name in data)) {
     146                    data[name] = value;
     147                }
     148            }
     149        });
     150
     151        const langs = [];
     152        const flags = [];
     153
     154        $('#flag-style_wrapper .style-language:not(.cloned)').each(function () {
     155            const lang = $(this)
     156                .find('.change_language input[name="style_change_language[]"]')
     157                .val();
     158            const flag = $(this)
     159                .find('.change_flag input[name="style_change_flag[]"]')
     160                .val();
     161
     162
     163            if (lang && flag) {
     164                langs.push(lang);
     165                flags.push(flag);
     166            }
     167        });
     168
     169        data.style_change_language = langs;
     170        data.style_change_flag = flags;
     171
     172        console.log('CLEAN DATA:', data);
     173
    127174        console.log(data);
    128175        console.log(conveythis_plugin_ajax.ajax_url);
     
    320367            'code3': 'eng',
    321368            'flag': 'R04',
    322             'flag_codes': {'us': 'United States of America', 'gb': ' United Kingdom', 'ca': 'Canada'}
     369            'flag_codes': {'gb': ' United Kingdom', 'ca': 'Canada', 'au': 'Australia'}
    323370        },
    324371        704: {'title_en': 'Afrikaans', 'title': 'Afrikaans', 'code2': 'af', 'code3': 'afr', 'flag': '7xS'},
    325372        705: {'title_en': 'Albanian', 'title': 'Shqip', 'code2': 'sq', 'code3': 'sqi', 'flag': '5iM'},
    326373        706: {'title_en': 'Amharic', 'title': 'አማርኛ', 'code2': 'am', 'code3': 'amh', 'flag': 'ZH1'},
    327         707: {'title_en': 'Arabic', 'title': 'العربية', 'code2': 'ar', 'code3': 'ara', 'flag': 'J06'},
     374        707: {
     375            'title_en': 'Arabic',
     376            'title': 'العربية',
     377            'code2': 'ar',
     378            'code3': 'ara',
     379            'flag': 'J06',
     380            'flag_codes': {
     381                'bh': 'Bahrain',
     382                'iq': 'Iraq',
     383                'jo': 'Jordan',
     384                'kw': 'Kuwait',
     385                'lb': 'Lebanon',
     386                'om': 'Oman',
     387                'ps': 'Palestine',
     388                'qa': 'Qatar',
     389                'sy': 'Syria',
     390                'ae': 'United Arab Emirates',
     391                'ye': 'Yemen',
     392
     393
     394                'dz': 'Algeria',
     395                'td': 'Chad',
     396                'km': 'Comoros',
     397                'dj': 'Djibouti',
     398                'eg': 'Egypt',
     399                'ly': 'Libya',
     400                'mr': 'Mauritania',
     401                'ma': 'Morocco',
     402                'so': 'Somalia',
     403                'sd': 'Sudan',
     404                'tn': 'Tunisia'
     405            }
     406        },
    328407        708: {'title_en': 'Armenian', 'title': 'Հայերեն', 'code2': 'hy', 'code3': 'hye', 'flag': 'q9U'},
    329408        709: {'title_en': 'Azerbaijan', 'title': 'Azərbaycanca', 'code2': 'az', 'code3': 'aze', 'flag': 'Wg1'},
     
    337416        717: {'title_en': 'Catalan', 'title': 'Català', 'code2': 'ca', 'code3': 'cat', 'flag': 'Pw6'},
    338417        718: {'title_en': 'Cebuano', 'title': 'Cebuano', 'code2': 'ceb', 'code3': 'ceb', 'flag': ''},
    339         719: {'title_en': 'Chinese (Simplified)', 'title': '简体', 'code2': 'zh', 'code3': 'zh-sim', 'flag': 'Z1v'},
    340         796: {'title_en': 'Chinese (Traditional)', 'title': '繁體', 'code2': 'zh-tw', 'code3': 'zh-tra', 'flag': 'Z1v'},
     418        719: {
     419            'title_en': 'Chinese (Simplified)',
     420            'title': '简体',
     421            'code2': 'zh',
     422            'code3': 'zh-sim',
     423            'flag': 'Z1v',
     424            'flag_codes': {
     425                'sg': 'Singapore',
     426                'my': 'Malaysia'
     427            }
     428        },
     429        796: {
     430            'title_en': 'Chinese (Traditional)',
     431            'title': '繁體',
     432            'code2': 'zh-tw',
     433            'code3': 'zh-tra',
     434            'flag': 'Z1v',
     435            'flag_codes': {
     436                'tw': 'Taiwan',
     437                'hk': 'Hong Kong',
     438                'mo': 'Macau'
     439            }
     440        },
    341441        720: {'title_en': 'Croatian', 'title': 'Hrvatski', 'code2': 'hr', 'code3': 'hrv', 'flag': '7KQ'},
    342442        721: {'title_en': 'Czech', 'title': 'Čeština', 'code2': 'cs', 'code3': 'cze', 'flag': '1ZY'},
     
    353453            'flag': 'nM4'
    354454        },
    355         727: {'title_en': 'French', 'title': 'Français', 'code2': 'fr', 'code3': 'fre', 'flag': 'E77'},
     455        727: {'title_en': 'French', 'title': 'Français', 'code2': 'fr', 'code3': 'fre', 'flag': 'E77',
     456            'flag_codes': {
     457            'ca': 'Canada'
     458        }
     459        },
    356460        728: {'title_en': 'Galician', 'title': 'Galego', 'code2': 'gl', 'code3': 'glg', 'flag': 'A5d'},
    357461        729: {'title_en': 'Georgian', 'title': 'ქართული', 'code2': 'ka', 'code3': 'kat', 'flag': '8Ou'},
     
    416520            'code3': 'spa',
    417521            'flag': 'A5d',
    418             'flag_codes': {'mx': 'Mexico', 'ar': 'Argentina', 'co': 'Colombia', 'es': 'Spain'}
     522            'flag_codes': {'mx': 'Mexico', 'ar': 'Argentina', 'co': 'Colombia'}
    419523        },
    420524        778: {'title_en': 'Sundanese', 'title': 'Basa Sunda', 'code2': 'su', 'code3': 'sun', 'flag': 'Wh1'},
     
    507611    //
    508612
    509     $('.ui.dropdown').dropdown(
    510         {
    511             onChange: function (e) {
    512                 if ($(this).hasClass('widget-trigger')) {
    513                     hideTargetLanguage();
    514                     conveythisSettings.view();
    515                 }
    516                 showDnsRecords();
    517             }
    518         }
    519     );
     613    $('.ui.dropdown').dropdown({
     614        onChange: function (value) {
     615
     616            if ($(this).hasClass('widget-trigger')) {
     617                hideTargetLanguage();
     618            }
     619
     620            if (typeof conveythisSettings !== 'undefined' && conveythisSettings.view) {
     621                conveythisSettings.view();
     622            }
     623
     624            showDnsRecords();
     625        }
     626    });
    520627
    521628    conveythisSettings.effect(function () {
     
    563670        $(document).find('.conveythis-delete-page').on('click', function (e) {
    564671            e.preventDefault();
    565             $(this).parent().remove();
     672            const $parent = $(this).parent();
     673            $parent.remove();
     674            updateStyleLanguageDropdowns();
    566675        });
    567676
     
    589698            e.preventDefault();
    590699            $(this).parent().remove();
     700            updateStyleLanguageDropdowns();
    591701        });
    592702
     
    597707        e.preventDefault();
    598708
    599         if ($(".style-language").length == 4) {
     709        if ($(".style-language").length == 8) {
    600710            $('#add_flag_style').prop("disable", true);
    601711            return;
    602712        }
    603713
    604         let $rule_style = $('.cloned').clone()
    605 
    606         $rule_style.removeClass('cloned')
    607         $rule_style.find('.change_language').prepend('<input type="hidden" name="style_change_language[]" value="">')
    608         $rule_style.find('.change_flag').prepend('<input type="hidden" name="style_change_flag[]"  value="">')
     714        $rule_style = $('.cloned').clone();
     715        $rule_style.removeClass('cloned');
     716
     717        $rule_style.find('.change_language input[type="hidden"]').remove();
     718        $rule_style.find('.change_flag input[type="hidden"]').remove();
     719
     720        $rule_style.find('.change_language')
     721            .prepend('<input type="hidden" name="style_change_language[]" value="">');
     722        $rule_style.find('.change_flag')
     723            .prepend('<input type="hidden" name="style_change_flag[]" value="">');
     724
    609725        $("#flag-style_wrapper").append($rule_style);
     726        sortFlagsByLanguage();
    610727
    611728        $(document).find('.conveythis-delete-page').on('click', function (e) {
     
    616733        $('.ui.dropdown').dropdown();
    617734        sortFlagsByLanguage();
     735        updateStyleLanguageDropdowns();
    618736    });
    619737
     
    12271345
    12281346                });
     1347                updateStyleLanguageDropdowns();
    12291348            },
     1349        });
     1350    }
     1351
     1352    // Prevents the user from selecting same language twice
     1353    function updateStyleLanguageDropdowns() {
     1354
     1355        const used = [];
     1356
     1357        $('#flag-style_wrapper .style-language:not(.cloned) .ui.dropdown.change_language').each(function () {
     1358            const val = $(this).dropdown('get value');
     1359            if (val) {
     1360                used.push(String(val));
     1361            }
     1362        });
     1363
     1364
     1365        $('#flag-style_wrapper .style-language:not(.cloned) .ui.dropdown.change_language').each(function () {
     1366            const current = String($(this).dropdown('get value') || '');
     1367            const $items = $(this).find('.menu .item');
     1368
     1369            $items.each(function () {
     1370                const val = String($(this).data('value') || '');
     1371
     1372                if (used.includes(val) && val !== current) {
     1373
     1374                    $(this)
     1375                        .addClass('disabled')
     1376                        .css({ 'pointer-events': 'none', opacity: 0.4 });
     1377                } else {
     1378
     1379                    $(this)
     1380                        .removeClass('disabled')
     1381                        .css({ 'pointer-events': '', opacity: '' });
     1382                }
     1383            });
    12301384        });
    12311385    }
  • conveythis-translate/trunk/changelog.txt

    r3394560 r3408258  
    11== Changelog ==
     2= 268.9 =
     3* Enhanced Change Flag feature with broader functionality.
     4
    25= 268.8 =
    36* Now elements can be excluded using their class attribute.
  • conveythis-translate/trunk/config.php

    r3394560 r3408258  
    77$dev_server = 'default';
    88
    9 //$dev_server = 3;
     9//$dev_server = 4;
    1010
    1111$allowed_app_servers = array(
  • conveythis-translate/trunk/index.php

    r3394560 r3408258  
    44Plugin URI: https://www.conveythis.com/?utm_source=widget&utm_medium=wordpress
    55Description: Translate your WordPress site into over 100 languages using professional and instant machine translation technology. ConveyThis will help provide you with an SEO-friendy, multilingual website in minutes with no coding required.
    6 Version: 268.8
     6Version: 268.9
    77
    88Author: ConveyThis Translate Team
Note: See TracChangeset for help on using the changeset viewer.