Plugin Directory

Changeset 1866057


Ignore:
Timestamp:
04/29/2018 04:32:04 PM (8 years ago)
Author:
ndelilovic
Message:

Added front-end language selection for german, english and bosnian
Updated assets with new options

Location:
salah-widget
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • salah-widget/trunk/readme.txt

    r1865866 r1866057  
    1515The widget shows the prayer/fasting time on your website using the local WordPress timezone and the provided salah.csv file (see installation description).
    1616
     17Front-end language support for:
     18 - English
     19 - German
     20 - Bosnian
     21
    1722== Installation ==
    1823
     
    26318. Enter the name of your city in the Salah Widget settings
    27329. Choose a Theme
     3310. Select the front-end language
    283410. [Save](https://plugins.svn.wordpress.org/salah-widget/assets/save_widget.png) your Salah Widget settings
    2935
     
    4450= 1.1 =
    4551* Stable version.
    46 * Support for german language.
     52* Added front-end language selection for: english, german, bosnian
  • salah-widget/trunk/salah-widget.php

    r1865866 r1866057  
    3232        $defaults = array(
    3333            'salah_city' => $timezone,
    34             'select' => 'Classic'
     34            'select_theme' => 'Classic',
     35            'select_language' => 'English'
    3536        );
    3637
     
    3839        $date_time->setTimezone(new DateTimeZone($timezone));
    3940
    40         $current_date = $date_time->format('d') . "." . $date_time->format('m') . "." . $date_time->format('Y');
    41         $current_time = $date_time->format('H') . ":" . $date_time->format('i') . ":" . $date_time->format('s');
    42         $display_date_time = '<br><b>' . $current_date . " - " . $current_time . '</b><br>' . '(' . __('Please ensure that the displayed date and time are same with your local/city date and time, if not change the Timezone in your WordPress settings') . ' !)';
     41        $current_date = $date_time->format('d') . '.' . $date_time->format('m') . '.' . $date_time->format('Y');
     42        $current_time = $date_time->format('H') . ':' . $date_time->format('i') . ':' . $date_time->format('s');
     43        $display_date_time = '<br><b>' . $current_date . ' - ' . $current_time . '</b><br>' . '(' . __('Please ensure that the displayed date and time are same with your local/city date and time, if not change the Timezone in your WordPress settings') . ' !)';
    4344
    4445        ?>
     
    4748
    4849        ?>
    49         <label for="<?php echo $this->get_field_id('salah_city'); ?>"><?php _e('Add');
     50        <label for='<?php echo $this->get_field_id('salah_city'); ?>'><?php _e('Add');
    5051            echo ' <b>salah.csv</b> ';
    5152            _e('document');
     
    6263
    6364        <p>
    64             <label for="<?php echo $this->get_field_id('salah_city'); ?>"><?php _e('Enter Location');
     65            <label for='<?php echo $this->get_field_id('salah_city'); ?>'><?php _e('Enter Location');
    6566                echo ':'; ?></label>
    66             <label for="<?php echo esc_attr($this->get_field_id('salah_city')); ?>"></label>
    67             <input class="widefat" id="<?php echo esc_attr($this->get_field_id('salah_city')); ?>"
    68                    name="<?php echo esc_attr($this->get_field_name('salah_city')); ?>" type="text"
    69                    value="<?php echo esc_attr($salah_city); ?>"/>
     67            <label for='<?php echo esc_attr($this->get_field_id('salah_city')); ?>'></label>
     68            <input class='widefat' id='<?php echo esc_attr($this->get_field_id('salah_city')); ?>'
     69                   name='<?php echo esc_attr($this->get_field_name('salah_city')); ?>' type='text'
     70                   value='<?php echo esc_attr($salah_city); ?>'/>
    7071        </p>
    7172
    7273        <p>
    73             <label for="<?php echo $this->get_field_id('select'); ?>"><?php _e('Select Theme');
     74            <label for='<?php echo $this->get_field_id('select_theme'); ?>'><?php _e('Select Theme');
    7475                echo ':'; ?></label>
    75             <select name="<?php echo $this->get_field_name('select'); ?>"
    76                     id="<?php echo $this->get_field_id('select'); ?>" class="widefat">
     76            <select name='<?php echo $this->get_field_name('select_theme'); ?>'
     77                    id='<?php echo $this->get_field_id('select_theme'); ?>' class="widefat">
    7778                <?php
    7879                // Your options array
     
    8788                // Loop through options and add each one to the select dropdown
    8889                foreach ($options as $key => $name) {
    89                     echo '<option value="' . esc_attr($key) . '" id="' . esc_attr($key) . '" ' . selected($select, $key, false) . '>' . $name . '</option>';
     90                    echo '<option value="' . esc_attr($key) . '" id="' . esc_attr($key) . '" ' . selected($select_theme, $key, false) . '>' . $name . '</option>';
    9091
    9192                } ?>
     
    9394        </p>
    9495
     96        <p>
     97            <label for='<?php echo $this->get_field_id('select_language'); ?>'><?php _e('Select Frontend Language');
     98                echo ':'; ?></label>
     99            <select name='<?php echo $this->get_field_name('select_language'); ?>'
     100                    id='<?php echo $this->get_field_id('select_language'); ?>' class="widefat">
     101                <?php
     102                // Your options array
     103                $options = array(
     104                    'en_language' => __('English'),
     105                    'de_language' => __('German'),
     106                    'bs_language' => __('Bosnian')
     107                );
     108
     109                // Loop through options and add each one to the select dropdown
     110                foreach ($options as $key => $name) {
     111                    echo '<option value="' . esc_attr($key) . '" id="' . esc_attr($key) . '" ' . selected($select_language, $key, false) . '>' . $name . '</option>';
     112
     113                } ?>
     114            </select>
     115        </p>
     116
    95117        <?php
    96118    }
     
    100122        $instance = $old_instance;
    101123        $instance['salah_city'] = isset($new_instance['salah_city']) ? wp_strip_all_tags($new_instance['salah_city']) : '';
    102         $instance['select'] = isset($new_instance['select']) ? wp_strip_all_tags($new_instance['select']) : '';
     124        $instance['select_theme'] = isset($new_instance['select_theme']) ? wp_strip_all_tags($new_instance['select_theme']) : '';
     125        $instance['select_language'] = isset($new_instance['select_language']) ? wp_strip_all_tags($new_instance['select_language']) : '';
    103126        return $instance;
    104127    }
     
    107130    public function widget($args, $instance)
    108131    {
     132        global $en_language;
     133        global $de_language;
     134        global $bs_language;
     135
    109136        extract($args);
    110137
    111138        $salah_city = !empty($instance['salah_city']) ? apply_filters('widget_title', $instance['salah_city']) : 'Europe/Vienna';
    112         $salah_theme = !empty($instance['select']) ? $instance['select'] : 'classicTable';
     139        $salah_theme = !empty($instance['select_theme']) ? $instance['select_theme'] : 'classicTable';
     140        $salah_language = !empty($instance['select_language']) ? $instance['select_language'] : 'en_language';
     141
    113142        $file_id = get_option('salah');
    114143        $file = get_attached_file($file_id);
     
    118147            $current_date = date('d') . '/' . date('m') . '/' . date('Y');
    119148            $csv_data = file_get_contents($file);
    120             $csv_data = iconv("windows-1250", "utf-8", $csv_data);
     149            $csv_data = iconv('windows-1250', 'utf-8', $csv_data);
    121150
    122151            $lines = explode("\n", $csv_data); // split data by new lines
     
    134163            }
    135164        } else {
    136             $date = "Error";
    137             $fajr = "Error";
    138             $sunrise = "Error";
    139             $dhuhr = "Error";
    140             $asr = "Error";
    141             $maghrib = "Error";
    142             $isha = "Error";
     165            $date = 'Error';
     166            $fajr = 'Error';
     167            $sunrise = 'Error';
     168            $dhuhr = 'Error';
     169            $asr = 'Error';
     170            $maghrib = 'Error';
     171            $isha = 'Error';
    143172        }
     173
     174        $selected_language = null;
     175
     176        switch ($salah_language) {
     177            case 'en_language':
     178                $selected_language = $en_language;
     179                break;
     180            case 'de_language':
     181                $selected_language = $de_language;
     182                break;
     183            case 'bs_language':
     184                $selected_language = $bs_language;
     185                break;
     186        }
     187
    144188
    145189        echo $before_widget;
     
    147191        echo '<thead>';
    148192        echo '<tr>';
    149         echo '<th colspan="4">' . __('Salah time for ') . $salah_city . '<br>' . $date . '</th>';
     193        echo '<th colspan="4">' . $selected_language['Salah time for '] . $salah_city . '<br>' . $date . '</th>';
    150194        echo '</tr>';
    151195        echo '</thead>';
    152196        echo '<tbody>';
    153197        echo '<tr>';
    154         echo '<td>' . __('Fajr') . '</td>';
     198        echo '<td>' . $selected_language['Fajr'] . '</td>';
    155199        echo '<td>' . $fajr . '</td>';
    156         echo '<td>' . __('Asr') . '</td>';
     200        echo '<td>' .$selected_language['Asr'] . '</td>';
    157201        echo '<td>' . $asr . '</td>';
    158202        echo '</tr>';
    159203        echo '<tr>';
    160         echo '<td>' . __('Sunrise') . '</td>';
     204        echo '<td>' . $selected_language['Sunrise'] . '</td>';
    161205        echo '<td>' . $sunrise . '</td>';
    162         echo '<td>' . __('Maghrib') . '</td>';
     206        echo '<td>' . $selected_language['Maghrib'] . '</td>';
    163207        echo '<td >' . $maghrib . '</td>';
    164208        echo '</tr>';
    165209        echo '<tr>';
    166         echo '<td>' . __('Dhuhr') . '</td>';
     210        echo '<td>' . $selected_language['Dhuhr'] . '</td>';
    167211        echo '<td>' . $dhuhr . '</td>';
    168         echo '<td>' . __('Isha') . '</td>';
     212        echo '<td>' . $selected_language['Isha'] . '</td>';
    169213        echo '<td>' . $isha . '</td>';
    170214        echo '</tr>';
     
    175219}
    176220
     221$en_language = [
     222    'Salah time for ' => 'Salah time for ',
     223    'Fajr' => 'Fajr',
     224    'Asr' => 'Asr',
     225    'Sunrise' => 'Sunrise',
     226    'Maghrib' => 'Maghrib',
     227    'Dhuhr' => 'Dhuhr',
     228    'Isha' => 'Isha'
     229];
     230
     231$de_language = [
     232    'Salah time for ' => 'Gebetszeiten für ',
     233    'Fajr' => 'Morgengebet',
     234    'Asr' => 'Nachmittagsgebet',
     235    'Sunrise' => 'Sonnenaufgang',
     236    'Maghrib' => 'Abendgebet',
     237    'Dhuhr' => 'Mittagsgebet',
     238    'Isha' => 'Nachtgebet'
     239];
     240
     241$bs_language = [
     242    'Salah time for ' => 'Vaktija za ',
     243    'Fajr' => 'Vaktija za',
     244    'Asr' => 'Ikindija',
     245    'Sunrise' => 'Izlazak sunca',
     246    'Maghrib' => 'Akšam',
     247    'Dhuhr' => 'Podne',
     248    'Isha' => 'Jacija'
     249];
     250
    177251function register_salah_widget()
    178252{
Note: See TracChangeset for help on using the changeset viewer.