Ignore:
Timestamp:
03/17/2009 09:07:25 AM (3 years ago)
Author:
ofer
Message:

Initial commit of auto-translate feature

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/transposh_widget.php

    r59 r68  
    3636 
    3737                global $wp_rewrite; 
    38          
     38 
    3939                $ref=getenv('HTTP_REFERER'); 
    4040                $lang = $_POST[LANG_PARAM]; 
    4141 
    42         //remove existing language settings.  
     42        //remove existing language settings. 
    4343        $ref = cleanup_url($ref); 
    44          
     44 
    4545                if($lang != "none") 
    4646                { 
     
    100100 
    101101    $is_showing_languages = FALSE; 
    102      
     102 
    103103        echo $before_widget . $before_title . __(no_translate("Transposh")) . $after_title; 
    104              
     104 
    105105        switch ($options['style']) { 
    106106                case 1: // flags 
    107107            //keep the flags in the same direction regardless of the overall page direction 
    108             echo "<div style=\"text-align: left;\" class=\"" . NO_TRANSLATE_CLASS . "\" >";  
     108            echo "<div style=\"text-align: left;\" class=\"" . NO_TRANSLATE_CLASS . "\" >"; 
    109109 
    110110            global $plugin_url; 
    111111            $using_permalinks = $wp_rewrite->using_permalinks(); 
    112              
     112 
    113113                        foreach($languages as $code => $lang2) 
    114114                        { 
    115115                                list($language,$flag) = explode (",",$lang2); 
    116116 
    117                 //remove any language identifier  
     117                //remove any language identifier 
    118118                $page_url = cleanup_url($page_url); 
    119                  
     119 
    120120                                //Only show languages which are viewable or (editable and the user is a translator) 
    121121                                if(strstr($viewable_langs, $code) || 
     
    123123                                { 
    124124                                        $page_url = rewrite_url_lang_param($page_url, $code, $is_edit, !$using_permalinks); 
    125                      
     125 
    126126                                        echo "<a href=\"" . $page_url . "\"> 
    127127                         <img src=\"$plugin_url/flags/$flag.png\" title=\"$language\" alt=\"$language\" 
     
    131131                        } 
    132132            echo "</div>"; 
    133              
     133 
    134134                        // this is the form for the edit... 
    135135                        echo "<form action=\"$page_url\" method=\"post\">"; 
     
    139139 
    140140            echo "<form action=\"$page_url\" method=\"post\">"; 
    141             echo "<span class=\"" . NO_TRANSLATE_CLASS . "\" >"; 
     141            echo "<span class=\"" .NO_TRANSLATE_CLASS . "\" >"; 
    142142                        echo "<select name=\"lang\"     id=\"lang\" onchange=\"Javascript:this.form.submit();\">"; 
    143143                        echo "<option value=\"none\">[Language]</option>"; 
     
    171171                "\" onClick=\"this.form.submit();\"/>&nbsp;Edit Translation"; 
    172172        } 
    173          
     173 
    174174        echo "<input type=\"hidden\" name=\"transposh_widget_posted\" value=\"1\"/>"; 
    175175    } 
     
    181181 
    182182    echo "</form>"; 
     183    echo "<button onClick=\"do_auto_translate();\">translate all</button>"; 
    183184 
    184185    echo $after_widget; 
    185186} 
    186187 
    187  
    188 /* 
    189  *Remove from url any language (or editing) params that were added for our use. 
    190  *Return the scrubed url 
     188/* 
     189 * Remove from url any language (or editing) params that were added for our use. 
     190 * Return the scrubed url 
    191191 */ 
    192192function cleanup_url($url) 
    193193{ 
    194194    global $home_url, $home_url_quoted; 
    195      
     195 
    196196    //cleanup previous lang & edit parameter from url 
    197197    $url = preg_replace("/(" . LANG_PARAM . "|" . EDIT_PARAM . ")=[^&]*/i", "", $url); 
    198      
    199      
     198 
     199 
    200200    if(!$home_url) 
    201201    { 
     
    203203        init_global_vars(); 
    204204    } 
    205      
     205 
    206206    //cleanup lang identifier in permalinks 
    207207    $url = preg_replace("/$home_url_quoted\/(..\/)/", "$home_url/",  $url); 
     
    245245    echo '<option ' . ($style == 1 ? 'selected="selected"' : '') . 
    246246        'value="1">Flags</option>'; 
    247      
     247 
    248248    echo '</select></label></p> 
    249249          <input type="hidden" name="transposh-submit" id="transposh-submit" value="1" />'; 
    250      
    251 } 
    252  
     250 
     251} 
    253252 
    254253//Register callback for WordPress events 
     
    256255add_action('widgets_init', 'transposh_widget_init'); 
    257256 
    258  
    259257?> 
Note: See TracChangeset for help on using the changeset viewer.