Plugin Directory

Changeset 3465020


Ignore:
Timestamp:
02/19/2026 11:03:39 AM (2 weeks ago)
Author:
lenasterg
Message:

accesibility fixes

Location:
ls-gtrans-widget
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • ls-gtrans-widget/trunk/class-ls-gtrans-widget.php

    r3212212 r3465020  
    33 * Ls_Gtrans_Widget Class
    44 *
    5  * @version 2.1
     5 * A custom WordPress widget that provides a Google Translate dropdown.
     6 *
     7 * @package    LS_Gtrans
     8 * @version    2.2
     9 * @author     lenasterg
    610 */
    711class Ls_Gtrans_Widget extends WP_Widget {
     
    913    /**
    1014     * Constructor.
     15     * * Sets up the widget's unique ID, title, and description.
    1116     */
    1217    public function __construct() {
    1318        $widget_ops = array(
    1419            'classname'   => 'ls_gtrans_widget',
    15             'description' => __( 'Drop-down with more than 25 languages', 'ls-gtrans-widget' ),
     20            'description' => __( 'Drop-down with customizable languages', 'ls-gtrans-widget' ),
    1621        );
    1722        parent::__construct( 'ls_gtrans_widget', __( 'Translate via Google', 'ls-gtrans-widget' ), $widget_ops );
     
    1924
    2025    /**
    21      * Outputs the widget content.
     26     * Retrieve the list of available languages.
     27     * * This list can be modified by third-party developers using the provided filter.
    2228     *
    23      * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
     29     * @since 2.2
     30     * @return array Associative array of language codes and their display names.
     31     */
     32    public function get_languages() {
     33        $languages = array(
     34            'sq' => __( 'Albanian', 'ls-gtrans-widget' ),
     35            'bg' => __( 'Bulgarian', 'ls-gtrans-widget' ),
     36            'hr' => __( 'Croatian', 'ls-gtrans-widget' ),
     37            'cs' => __( 'Czech', 'ls-gtrans-widget' ),
     38            'da' => __( 'Danish', 'ls-gtrans-widget' ),
     39            'nl' => __( 'Dutch', 'ls-gtrans-widget' ),
     40            'en' => __( 'English', 'ls-gtrans-widget' ),
     41            'et' => __( 'Estonian', 'ls-gtrans-widget' ),
     42            'fi' => __( 'Finnish', 'ls-gtrans-widget' ),
     43            'fr' => __( 'French', 'ls-gtrans-widget' ),
     44            'de' => __( 'German', 'ls-gtrans-widget' ),
     45            'el' => __( 'Greek', 'ls-gtrans-widget' ),
     46            'hu' => __( 'Hungarian', 'ls-gtrans-widget' ),
     47            'it' => __( 'Italian', 'ls-gtrans-widget' ),
     48            'lv' => __( 'Latvian', 'ls-gtrans-widget' ),
     49            'lt' => __( 'Lithuanian', 'ls-gtrans-widget' ),
     50            'mt' => __( 'Maltese', 'ls-gtrans-widget' ),
     51            'no' => __( 'Norwegian', 'ls-gtrans-widget' ),
     52            'pl' => __( 'Polish', 'ls-gtrans-widget' ),
     53            'pt' => __( 'Portuguese', 'ls-gtrans-widget' ),
     54            'ro' => __( 'Romanian', 'ls-gtrans-widget' ),
     55            'ru' => __( 'Russian', 'ls-gtrans-widget' ),
     56            'sr' => __( 'Serbian', 'ls-gtrans-widget' ),
     57            'sk' => __( 'Slovak', 'ls-gtrans-widget' ),
     58            'sl' => __( 'Slovenian', 'ls-gtrans-widget' ),
     59            'es' => __( 'Spanish', 'ls-gtrans-widget' ),
     60            'sv' => __( 'Swedish', 'ls-gtrans-widget' ),
     61            'tr' => __( 'Turkish', 'ls-gtrans-widget' ),
     62            'uk' => __( 'Ukrainian', 'ls-gtrans-widget' ),
     63        );
     64
     65        /**
     66         * Filters the available languages for the Google Translate widget.
     67         *
     68         * @param array $languages Array of language codes and labels.
     69         */
     70        return apply_filters( 'ls_gtrans_available_languages', $languages );
     71    }
     72
     73    /**
     74     * Outputs the content of the widget.
     75     *
     76     * @param array $args     Display arguments including 'before_title', 'after_title', etc.
    2477     * @param array $instance The settings for the particular instance of the widget.
    2578     */
    2679    public function widget( $args, $instance ) {
     80   
     81        global $wp;
     82        $current_url = home_url( add_query_arg( array(), $wp->request ) );
     83       
    2784        $title = empty( $instance['title'] ) ? __( 'Translate', 'ls-gtrans-widget' ) : apply_filters( 'widget_title', $instance['title'] );
     85        $select_id = $this->get_field_id( 'ls_gtrans_sel' );
     86        $languages = $this->get_languages();
    2887
    29         // Output the widget wrapper.
    3088        echo isset( $args['before_widget'] ) ? $args['before_widget'] : '';
    3189
    32         // Output the widget title.
    3390        if ( ! empty( $title ) ) {
    34             echo isset( $args['before_title'] ) ? $args['before_title'] : '';
    35             echo esc_html( $title ); // Escaped title
    36             echo isset( $args['after_title'] ) ? $args['after_title'] : '';
     91            echo ( isset( $args['before_title'] ) ? $args['before_title'] : '' )
     92                 . esc_html( $title )
     93                 . ( isset( $args['after_title'] ) ? $args['after_title'] : '' );
    3794        }
     95        ?>
     96        <form action="https://translate.google.com/translate" method="get" target="_top">
     97            <label for="<?php echo esc_attr( $select_id ); ?>" class="screen-reader-text">
     98                <?php esc_html_e( 'Select a language to translate this page', 'ls-gtrans-widget' ); ?>
     99            </label>
    38100
    39         // Output the form.
    40         ?>
    41         <form name="ls_gtrans_form">
     101            <input type="hidden" name="hl" value="en">
     102            <input type="hidden" name="sl" value="auto">
     103            <input type="hidden" name="u" value="<?php echo $current_url; ?>">
     104
    42105            <select
    43                 id="ls_gtrans_sel"
    44                 onchange="window.top.location.href = 'https://translate.google.com/translate?hl=en&sl=auto&tl=' + this.options[this.selectedIndex].value + '&u=' + encodeURIComponent(window.location.href);"
    45                 style="width: 200px; padding-left: 20px; background-image: url('<?php echo esc_url( plugins_url( '/images/google_logo.png', __FILE__ ) ); ?>'); background-repeat: no-repeat;">
     106                name="tl"
     107                id="<?php echo esc_attr( $select_id ); ?>"
     108                style="width: 100%; max-width: 200px; display: block; margin-bottom: 10px; padding-left: 25px; background: url('<?php echo esc_url( plugins_url( '/images/google_logo.png', __FILE__ ) ); ?>') no-repeat 5px center / 16px auto;">
     109               
    46110                <option value=""><?php esc_html_e( 'Select a language', 'ls-gtrans-widget' ); ?></option>
    47                 <option value="sq"><?php esc_html_e( 'Albanian', 'ls-gtrans-widget' ); ?></option>
    48                 <option value="bg"><?php esc_html_e( 'Bulgarian', 'ls-gtrans-widget' ); ?></option>
    49                 <option value="hr"><?php esc_html_e( 'Croatian', 'ls-gtrans-widget' ); ?></option>
    50                 <option value="cs"><?php esc_html_e( 'Czech', 'ls-gtrans-widget' ); ?></option>
    51                 <option value="da"><?php esc_html_e( 'Danish', 'ls-gtrans-widget' ); ?></option>
    52                 <option value="nl"><?php esc_html_e( 'Dutch', 'ls-gtrans-widget' ); ?></option>
    53                 <option value="en"><?php esc_html_e( 'English', 'ls-gtrans-widget' ); ?></option>
    54                 <option value="et"><?php esc_html_e( 'Estonian', 'ls-gtrans-widget' ); ?></option>
    55                 <option value="fi"><?php esc_html_e( 'Finnish', 'ls-gtrans-widget' ); ?></option>
    56                 <option value="fr"><?php esc_html_e( 'French', 'ls-gtrans-widget' ); ?></option>
    57                 <option value="de"><?php esc_html_e( 'German', 'ls-gtrans-widget' ); ?></option>
    58                 <option value="el"><?php esc_html_e( 'Greek', 'ls-gtrans-widget' ); ?></option>
    59                 <option value="hu"><?php esc_html_e( 'Hungarian', 'ls-gtrans-widget' ); ?></option>
    60                 <option value="it"><?php esc_html_e( 'Italian', 'ls-gtrans-widget' ); ?></option>
    61                 <option value="lv"><?php esc_html_e( 'Latvian', 'ls-gtrans-widget' ); ?></option>
    62                 <option value="lt"><?php esc_html_e( 'Lithuanian', 'ls-gtrans-widget' ); ?></option>
    63                 <option value="mt"><?php esc_html_e( 'Maltese', 'ls-gtrans-widget' ); ?></option>
    64                 <option value="no"><?php esc_html_e( 'Norwegian', 'ls-gtrans-widget' ); ?></option>
    65                 <option value="pl"><?php esc_html_e( 'Polish', 'ls-gtrans-widget' ); ?></option>
    66                 <option value="pt"><?php esc_html_e( 'Portuguese', 'ls-gtrans-widget' ); ?></option>
    67                 <option value="ro"><?php esc_html_e( 'Romanian', 'ls-gtrans-widget' ); ?></option>
    68                 <option value="ru"><?php esc_html_e( 'Russian', 'ls-gtrans-widget' ); ?></option>
    69                 <option value="sr"><?php esc_html_e( 'Serbian', 'ls-gtrans-widget' ); ?></option>
    70                 <option value="sk"><?php esc_html_e( 'Slovak', 'ls-gtrans-widget' ); ?></option>
    71                 <option value="sl"><?php esc_html_e( 'Slovenian', 'ls-gtrans-widget' ); ?></option>
    72                 <option value="es"><?php esc_html_e( 'Spanish', 'ls-gtrans-widget' ); ?></option>
    73                 <option value="sv"><?php esc_html_e( 'Swedish', 'ls-gtrans-widget' ); ?></option>
    74                 <option value="tr"><?php esc_html_e( 'Turkish', 'ls-gtrans-widget' ); ?></option>
    75                 <option value="uk"><?php esc_html_e( 'Ukrainian', 'ls-gtrans-widget' ); ?></option>
     111               
     112                <?php foreach ( $languages as $code => $label ) : ?>
     113                    <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $label ); ?></option>
     114                <?php endforeach; ?>
     115
    76116            </select>
     117
     118            <button type="submit" class="button">
     119                <?php esc_html_e( 'Translate', 'ls-gtrans-widget' ); ?>
     120            </button>
    77121        </form>
    78122        <?php
    79 
    80         // Output the closing widget wrapper.
    81123        echo isset( $args['after_widget'] ) ? $args['after_widget'] : '';
    82124    }
    83125
    84126    /**
    85      * Outputs the settings form in the admin.
     127     * Outputs the settings update form in the WordPress admin.
    86128     *
    87      * @param array $instance The current settings.
     129     * @param array $instance Current settings.
     130     * @return void
    88131     */
    89132    public function form( $instance ) {
     
    91134        ?>
    92135        <p>
    93             <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
    94                 <?php esc_html_e( 'Title', 'ls-gtrans-widget' ); ?>:
    95             </label>
    96             <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
    97                    name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
    98                    type="text"
    99                    value="<?php echo esc_attr( $title ); ?>" />
     136            <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'ls-gtrans-widget' ); ?>:</label>
     137            <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    100138        </p>
    101139        <?php
     
    103141
    104142    /**
    105      * Handles updating settings for the current widget instance.
     143     * Updates a particular instance of a widget.
    106144     *
    107      * @param array $new_instance New settings for this instance.
     145     * @param array $new_instance New settings for this instance as input by the user via form().
    108146     * @param array $old_instance Old settings for this instance.
    109      *
    110      * @return array Updated settings.
     147     * @return array Settings to be saved.
    111148     */
    112149    public function update( $new_instance, $old_instance ) {
    113         $instance          = $old_instance;
     150        $instance = $old_instance;
    114151        $instance['title'] = sanitize_text_field( $new_instance['title'] );
    115152        return $instance;
  • ls-gtrans-widget/trunk/index.php

    r3231120 r3465020  
    33 * Plugin Name: Ls Gtrans Widget
    44 * Author: lenasterg, NTS on cti.gr, sch.gr
    5  * Version: 2.1.1
     5 * Version: 2.2.0
    66 * Description: Widget with a select box for Google translation of the current page. Contains more than 25 European languages.
    77 * License: GPLv2 or later
  • ls-gtrans-widget/trunk/readme.txt

    r3231120 r3465020  
    55Tested up to: 6.7.1 
    66Requires PHP: 5.6 
    7 Stable tag: 2.1.1 
     7Stable tag: 2.2.0 
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html 
     
    3535
    3636= Does the plugin work with non-European languages? =
    37 This version supports over 25 European languages. For other languages, modifications to the code may be required.
     37This version supports over 25 European languages. For adding or removing languages, use `ls_gtrans_available_languages` filter.
    3838
    39 = Is it compatible with the latest versions of WordPress and PHP? =
    40 Yes, the plugin is tested up to WordPress 6.1.1 and PHP 8.1+.
    4139
    4240== Screenshots ==
     
    4644
    4745== Changelog ==
     46
     47= 2.2.0 =
     48* Accessibility fixes
     49* Extensibility, Added `ls_gtrans_available_languages` filter hook to allow developers to add or remove languages programmatically.
    4850
    4951= 2.1.1 =
Note: See TracChangeset for help on using the changeset viewer.