Changeset 3465020
- Timestamp:
- 02/19/2026 11:03:39 AM (2 weeks ago)
- Location:
- ls-gtrans-widget
- Files:
-
- 9 added
- 3 edited
-
tags/2.2.0 (added)
-
tags/2.2.0/class-ls-gtrans-widget.php (added)
-
tags/2.2.0/images (added)
-
tags/2.2.0/images/google_logo.png (added)
-
tags/2.2.0/index.php (added)
-
tags/2.2.0/licence.txt (added)
-
tags/2.2.0/readme.txt (added)
-
tags/2.2.0/screenshot-1.png (added)
-
tags/2.2.0/screenshot-2.png (added)
-
trunk/class-ls-gtrans-widget.php (modified) (5 diffs)
-
trunk/index.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ls-gtrans-widget/trunk/class-ls-gtrans-widget.php
r3212212 r3465020 3 3 * Ls_Gtrans_Widget Class 4 4 * 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 6 10 */ 7 11 class Ls_Gtrans_Widget extends WP_Widget { … … 9 13 /** 10 14 * Constructor. 15 * * Sets up the widget's unique ID, title, and description. 11 16 */ 12 17 public function __construct() { 13 18 $widget_ops = array( 14 19 'classname' => 'ls_gtrans_widget', 15 'description' => __( 'Drop-down with more than 25languages', 'ls-gtrans-widget' ),20 'description' => __( 'Drop-down with customizable languages', 'ls-gtrans-widget' ), 16 21 ); 17 22 parent::__construct( 'ls_gtrans_widget', __( 'Translate via Google', 'ls-gtrans-widget' ), $widget_ops ); … … 19 24 20 25 /** 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. 22 28 * 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. 24 77 * @param array $instance The settings for the particular instance of the widget. 25 78 */ 26 79 public function widget( $args, $instance ) { 80 81 global $wp; 82 $current_url = home_url( add_query_arg( array(), $wp->request ) ); 83 27 84 $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(); 28 87 29 // Output the widget wrapper.30 88 echo isset( $args['before_widget'] ) ? $args['before_widget'] : ''; 31 89 32 // Output the widget title.33 90 if ( ! empty( $title ) ) { 34 echo isset( $args['before_title'] ) ? $args['before_title'] : '';35 echo esc_html( $title ); // Escaped title36 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'] : '' ); 37 94 } 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> 38 100 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 42 105 <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 46 110 <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 76 116 </select> 117 118 <button type="submit" class="button"> 119 <?php esc_html_e( 'Translate', 'ls-gtrans-widget' ); ?> 120 </button> 77 121 </form> 78 122 <?php 79 80 // Output the closing widget wrapper.81 123 echo isset( $args['after_widget'] ) ? $args['after_widget'] : ''; 82 124 } 83 125 84 126 /** 85 * Outputs the settings form in theadmin.127 * Outputs the settings update form in the WordPress admin. 86 128 * 87 * @param array $instance The current settings. 129 * @param array $instance Current settings. 130 * @return void 88 131 */ 89 132 public function form( $instance ) { … … 91 134 ?> 92 135 <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 ); ?>" /> 100 138 </p> 101 139 <?php … … 103 141 104 142 /** 105 * Handles updating settings for the current widget instance.143 * Updates a particular instance of a widget. 106 144 * 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(). 108 146 * @param array $old_instance Old settings for this instance. 109 * 110 * @return array Updated settings. 147 * @return array Settings to be saved. 111 148 */ 112 149 public function update( $new_instance, $old_instance ) { 113 $instance = $old_instance;150 $instance = $old_instance; 114 151 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 115 152 return $instance; -
ls-gtrans-widget/trunk/index.php
r3231120 r3465020 3 3 * Plugin Name: Ls Gtrans Widget 4 4 * Author: lenasterg, NTS on cti.gr, sch.gr 5 * Version: 2. 1.15 * Version: 2.2.0 6 6 * Description: Widget with a select box for Google translation of the current page. Contains more than 25 European languages. 7 7 * License: GPLv2 or later -
ls-gtrans-widget/trunk/readme.txt
r3231120 r3465020 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 5.6 7 Stable tag: 2. 1.17 Stable tag: 2.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 35 35 36 36 = 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.37 This version supports over 25 European languages. For adding or removing languages, use `ls_gtrans_available_languages` filter. 38 38 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+.41 39 42 40 == Screenshots == … … 46 44 47 45 == 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. 48 50 49 51 = 2.1.1 =
Note: See TracChangeset
for help on using the changeset viewer.