Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 1 | <?php |
| 2 | error_reporting(E_ALL); |
| 3 | require_once('common.php'); |
| 4 | |
| 5 | function submit() { |
| 6 | header("Content-type: text/plain;charset=UTF-8"); |
| 7 | header(sprintf("Content-Disposition: attachment; filename=%s.diff", $_REQUEST['lang'])); |
Jonas Häggqvist | 04e454b | 2010-01-31 01:50:52 +0000 | [diff] [blame] | 8 | chdir('rockbox'); // chdir into the rockbox dir to get proper diffs |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 9 | |
| 10 | $i = 0; |
| 11 | do { |
| 12 | $filename = sprintf("apps/lang/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i); |
| 13 | $i++; |
| 14 | } while (file_exists($filename)); |
| 15 | |
| 16 | $fp = fopen($filename, 'w'); |
| 17 | $langs = array(); |
| 18 | if (file_exists(VERSIONS)) { |
| 19 | foreach(file(VERSIONS) as $line) { |
| 20 | list($lang, $version) = explode(":", trim($line)); |
| 21 | $langs[$lang] = $version; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // Write a header if one exists |
| 26 | $original_lines = file(sprintf("apps/lang/%s.lang", $_REQUEST['lang'])); |
| 27 | foreach($original_lines as $i => $line) { |
| 28 | if (substr($line, 0, 1) == "<") { break; } |
| 29 | fwrite($fp, $line); |
| 30 | } |
| 31 | |
| 32 | $original = parselangfile(sprintf("apps/lang/%s.lang.update", $_REQUEST['lang'])); |
| 33 | $english = parselangfile("apps/lang/english.lang"); |
| 34 | print("Copyright by individual Rockbox contributors\n"); |
| 35 | printf("See\nhttp://svn.rockbox.org/viewvc.cgi/trunk/apps/lang/%s.lang?view=log\nfor details.\n", $_REQUEST['lang']); |
| 36 | print("May be distributed under the terms of the GNU GPL version 2 or later\n"); |
| 37 | print("This file generated by http://translate.rockbox.org/\n\n"); |
| 38 | printf("This translation was based on SVN revision %d of the original.\n\n", $langs[$_REQUEST['lang']]); |
| 39 | |
| 40 | foreach($original as $id => $phrase) { |
| 41 | foreach(array('dest', 'voice') as $type) { |
| 42 | if (isset($_POST['phrases'][$id])) { |
| 43 | if (isset($_POST['phrases'][$id][$type])) |
| 44 | $phrase[$type] = $_POST['phrases'][$id][$type]; |
| 45 | else |
| 46 | unset($phrase[$type]); |
| 47 | } |
| 48 | } |
| 49 | if (strtolower($english[$id]['phrase']['desc']) == "deprecated") { |
| 50 | $phrase = $english[$id]; |
| 51 | } |
| 52 | fwrite($fp, printphrase($phrase)); |
| 53 | } |
| 54 | fclose($fp); |
| 55 | $cmd = sprintf("/usr/bin/diff -u -B -w apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename); |
| 56 | print(shell_exec($cmd)); |
| 57 | } |
| 58 | |
| 59 | submit(); |
| 60 | ?> |