Changeset 1345 in subversion


Ignore:
Timestamp:
Apr 30, 2008 9:16:56 AM (5 years ago)
Author:
thomasb
Message:

Remove short php tags + add option to download the localization file

Location:
trunk/translator
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/translator/func.php

    r1327 r1345  
    8484 
    8585 
     86function build_localization($lang, $file) 
     87{ 
     88        global $orig_values, $edit_values; 
     89         
     90        $array = $file == "messages.inc" ? '$messages' : '$labels'; 
     91        $fpath = $lang != "_NEW_" ? update_from_svn($lang, $file) : 'nope'; 
     92         
     93        if (!strstr($fpath, 'http') && !is_file($fpath)) 
     94                $fpath = realpath("./$file"); 
     95         
     96        $out = ""; 
     97        if ($fpath && ($fp = fopen($fpath, 'r'))) 
     98        { 
     99                while (!feof($fp)) 
     100                { 
     101                        $line = trim(fgets($fp)); 
     102                         
     103                        if (empty($line) && empty($out)) 
     104                                continue; 
     105                                 
     106                        $out .= str_replace('#lang', $lang, $line) . "\n"; 
     107                         
     108                        // reached begin of php array 
     109                        if (strstr($line, $array)) 
     110                                break; 
     111                } 
     112        } 
     113        else 
     114        { 
     115                $out .= '<?php' . "\n"; 
     116                $out .= $array . " = array();\n"; 
     117        } 
     118 
     119        foreach((array)$orig_values as $t_key => $t_value) 
     120        { 
     121                $t_value = get_input_value('t_'.$t_key); 
     122                if (empty($t_value) && isset($edit_values[$t_key])) 
     123                        $t_value = $edit_values[$t_key]; 
     124                if (!empty($t_value)) 
     125                        $out .= $array . "['$t_key'] = '" . addslashes($t_value) . "';\n"; 
     126        } 
     127         
     128        $out .= "\n?>\n"; 
     129        return $out; 
     130} 
     131 
     132 
    86133// -------- EOF func --------// 
    87134 
     
    94141$translated = !empty($_REQUEST['trans']); 
    95142 
     143// read reference file 
    96144if ($file && $lang) 
    97145        include(update_from_svn(ORIGINAL, $file)); 
     
    104152unset($labels, $messages); 
    105153 
     154// read current localization file 
     155if (!empty($lang) && !empty($file)) 
     156{ 
     157        if ($lang != "_NEW_") 
     158                @include(update_from_svn($lang, $file)); 
     159         
     160        if (!empty($labels)) 
     161                $edit_values = $labels; 
     162        else if (!empty($messages)) 
     163                $edit_values = $messages; 
     164        else 
     165                $edit_values = array(); 
     166                 
     167        unset($labels, $messages); 
     168} 
     169 
    106170?> 
  • trunk/translator/index.php

    r1340 r1345  
    1 <?php header("Content-Type: text/html; charset=UTF-8"); ?> 
     1<?php 
     2 
     3ob_start(); 
     4 
     5require_once 'func.php'; 
     6 
     7if (isset($_POST["download"]) && $file && $lang) 
     8{ 
     9        ob_end_clean(); 
     10         
     11        header("Content-Type: text/plain; charset=UTF-8"); 
     12        header("Cache-Control: private"); 
     13        header("Content-Disposition: attachment; filename=\"{$file}\""); 
     14         
     15        echo build_localization($lang, $file); 
     16        exit; 
     17} 
     18else 
     19        header("Content-Type: text/html; charset=UTF-8"); 
     20 
     21ob_end_clean(); 
     22 
     23?> 
    224<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    325<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="et"> 
     
    1537</div> 
    1638 
    17 <?php include('func.php'); ?> 
    18  
    1939<div id="bodycontent"> 
    2040 
    21 <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> 
     41<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    2242<fieldset> 
    2343<legend>What to translate</legend> 
     
    2646 
    2747<select name="file"> 
    28         <option value="labels.inc"<?=($file=='labels.inc'?' selected':'')?>>labels.inc</option> 
    29         <option value="messages.inc"<?=($file=='messages.inc'?' selected':'')?>>messages.inc</option> 
     48        <option value="labels.inc"<?php echo ($file=='labels.inc'?' selected':''); ?>>labels.inc</option> 
     49        <option value="messages.inc"<?php echo ($file=='messages.inc'?' selected':''); ?>>messages.inc</option> 
    3050</select> 
    3151 
    3252<div> 
    33 <input type="checkbox" name="trans" id="trans" value="1"<?=($translated?' checked':'')?> /> 
     53<input type="checkbox" name="trans" id="trans" value="1"<?php echo ($translated?' checked':''); ?> /> 
    3454<label for="trans">Show translated texts</label> 
    3555</div> 
     
    4060 
    4161<div id="translations"> 
    42 <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> 
     62<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    4363<input type="hidden" name="save" value="1" /> 
    4464<?php 
     
    5070        echo '<table border="0" cellspacing="0" class="translist" summary="">'; 
    5171        echo '<thead><tr><td>Label</td><td>Original</td><td>Translation</td></tr></thead><tbody>'; 
    52          
    53         if ($lang != "_NEW_") 
    54                 @include(update_from_svn($lang, $file)); 
    55                  
    56         if (!empty($labels)) 
    57                 $edit_values = $labels; 
    58         else if (!empty($messages)) 
    59                 $edit_values = $messages; 
    60         else 
    61                 $edit_values = array(); 
    6272         
    6373        $count = 0; 
     
    8494         
    8595        echo "</tbody></table>\n"; 
    86         echo '<p><input type="submit" class="button" name="translate" value="Create translation"/></p>'; 
     96        echo '<p><br /><input type="submit" class="button" name="translate" value="Create translation" />'; 
     97        echo '<span style="padding-left:1.5em"><input type="checkbox" name="download" value="1" checked="checked" />&nbsp;Download directly</a></p>'; 
     98        echo '<p class="hint">Save the localization file and post it to the <a href="http://lists.roundcube.net/dev">dev-mailing list</a></p>'; 
    8799 
    88100} 
     
    96108if (isset($_POST["save"]) && $file && $lang) 
    97109{ 
    98         $array = $file == "messages.inc" ? '$messages' : '$labels'; 
    99         $fpath = $lang != "_NEW_" ? update_from_svn($lang, $file) : 'nope'; 
    100          
    101         if (!strstr($fpath, 'http') && !is_file($fpath)) 
    102                 $fpath = realpath("./$file"); 
    103          
    104110        echo '<div id="resultsbox">'."<h3>Localization file</h3>\n"; 
    105111        echo '<form id="select_all" action="./"> 
    106112        <textarea id="results" name="text_area" rows="'.min(30, count($orig_values)).'" cols="130">'; 
    107  
    108         if ($fpath && ($fp = fopen($fpath, 'r'))) 
    109         { 
    110                 while (!feof($fp)) 
    111                 { 
    112                         $line = fgets($fp); 
    113                         echo htmlspecialchars(str_replace('#lang', $lang, rtrim($line))) . "\n"; 
    114                         if (strstr($line, $array)) 
    115                                 break; 
    116                 } 
    117         } 
    118         else 
    119         { 
    120                 echo "&lt;?php\n"; 
    121                 echo $array . " = array();\n"; 
    122         } 
    123  
    124         foreach($orig_values as $t_key => $t_value) 
    125         { 
    126                 $t_value = get_input_value('t_'.$t_key); 
    127                 if (empty($t_value) && isset($edit_values[$t_key])) 
    128                         $t_value = $edit_values[$t_key]; 
    129                 if (!empty($t_value)) 
    130                         echo $array . "['$t_key'] = '" . addslashes(htmlspecialchars($t_value, ENT_COMPAT, 'UTF-8')) . "';\n"; 
    131         } 
    132  
    133         echo "\n?&gt;</textarea>\n"; 
     113        echo htmlspecialchars(build_localization($lang, $file), ENT_COMPAT, 'UTF-8'); 
     114        echo "</textarea>\n"; 
    134115        echo '<p><input id="hilight" class="button" type="button" value="Select all" onclick="javascript:this.form.text_area.focus();this.form.text_area.select();" /></p>'; 
    135116        echo "\n</form></div>"; 
  • trunk/translator/labels.inc

    r1276 r1345  
    66 |                                                                       | 
    77 | Language file of the RoundCube Webmail client                         | 
    8  | Copyright (C) 2006, RoundQube Dev. - Switzerland                      | 
     8 | Copyright (C) 2008, RoundQube Dev. - Switzerland                      | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
  • trunk/translator/messages.inc

    r1276 r1345  
    66 |                                                                       | 
    77 | Language file of the RoundCube Webmail client                         | 
    8  | Copyright (C) 2006, RoundQube Dev. - Switzerland                      | 
     8 | Copyright (C) 2008, RoundQube Dev. - Switzerland                      | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
  • trunk/translator/styles.css

    r1340 r1345  
    7979} 
    8080 
     81.hint { 
     82        color: #999; 
     83} 
     84 
    8185#translations { 
    8286        margin: 20px 0; 
Note: See TracChangeset for help on using the changeset viewer.