Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 1 | <?php |
| 2 | define("PERL", '/usr/bin/perl'); |
| 3 | define("STATS", 'stats.dat'); |
| 4 | define("VERSIONS", 'versions.dat'); |
| 5 | define("SMALL_FLAGSIZE", '22'); |
| 6 | define("LARGE_FLAGSIZE", '150'); |
| 7 | |
Jonas Häggqvist | 02ff9a4 | 2010-01-31 01:48:25 +0000 | [diff] [blame] | 8 | require_once('templater.class.php'); |
| 9 | $smarty = new templater('/usr/share/php/smarty/libs'); |
| 10 | $smarty->assign('languages', languageinfo()); |
| 11 | $smarty->assign('updated', file_exists(STATS) ? filemtime(STATS) : 0); |
| 12 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 13 | function languageinfo() { |
| 14 | return parse_ini_file('languages.ini', true); |
| 15 | } |
| 16 | |
| 17 | function parselangfile($filename) { |
| 18 | $lines = @file($filename); |
| 19 | if (!is_array($lines)) { |
| 20 | return false; |
| 21 | } |
| 22 | $phrases = array(); |
| 23 | $empty = array( |
| 24 | 'source' => array(), |
| 25 | 'dest' => array(), |
| 26 | 'voice' => array(), |
| 27 | 'notes' => array(), |
| 28 | ); |
| 29 | $thisphrase = $empty; |
| 30 | |
| 31 | $pos = 'phrase'; |
| 32 | |
| 33 | foreach($lines as $lineno => $line) { |
| 34 | $line = trim($line); |
| 35 | |
| 36 | if (preg_match("/^### (.*)$/", $line, $matches)) { |
| 37 | if (strpos($matches[1], "The phrase is not used. Skipped") === false) { |
| 38 | $thisphrase['notes'][] = $matches[1]; |
| 39 | } |
| 40 | } |
| 41 | elseif ($pos == 'phrase' && preg_match("/^([^:]+): ?(.*)$/", $line, $matches)) { |
| 42 | $thisphrase[$pos][$matches[1]] = $matches[2]; |
| 43 | } |
| 44 | elseif ($pos != 'phrase' && preg_match("/^([^:]+): ?\"?([^\"]*)\"?$/", $line, $matches)) { |
| 45 | $thisphrase[$pos][$matches[1]] = $matches[2]; |
| 46 | } |
| 47 | |
| 48 | switch($line) { |
| 49 | case '</voice>': |
| 50 | case '</dest>': |
| 51 | case '</source>': |
| 52 | case '<phrase>': $pos = 'phrase'; break; |
| 53 | case '</phrase>': |
| 54 | $phrases[$thisphrase['phrase']['id']] = $thisphrase; |
| 55 | $thisphrase = $empty; |
| 56 | $pos = 'lang'; |
| 57 | break; |
| 58 | case '<source>': $pos = 'source'; break; |
| 59 | case '<dest>': $pos = 'dest'; break; |
| 60 | case '<voice>': $pos = 'voice'; break; |
| 61 | } |
| 62 | } |
| 63 | return $phrases; |
| 64 | } |
| 65 | |
| 66 | function printphrase($phrase) { |
| 67 | $ret = ''; |
| 68 | $ret .= sprintf("<phrase>\n id: %s\n desc:%s\n user:%s\n", |
| 69 | $phrase['phrase']['id'], |
| 70 | isset($phrase['phrase']['desc']) && $phrase['phrase']['desc'] != "" ? ' '.$phrase['phrase']['desc'] : '', |
| 71 | isset($phrase['phrase']['user']) && $phrase['phrase']['user'] != "" ? ' '.$phrase['phrase']['user'] : '' |
| 72 | ); |
| 73 | |
| 74 | foreach(array('source', 'dest', 'voice') as $field) { |
| 75 | $ret .= sprintf(" <%s>\n", $field); |
| 76 | if (isset($phrase[$field])) { |
| 77 | /* If '*' is empty, we don't catch it on the edit-page */ |
| 78 | if (!isset($phrase[$field]['*'])) { |
| 79 | $ret .= " *: \"\"\n"; |
| 80 | } |
| 81 | foreach($phrase[$field] as $target => $string) { |
| 82 | if ($target == 'desc' || $target == 'user' || $target == 'id') continue; |
| 83 | if (trim($string) == 'none') { $string = 'none'; } |
| 84 | elseif (strtolower(trim($string)) == 'deprecated') { $string = 'deprecated'; } |
| 85 | $format = ($string == 'none' || $string == 'deprecated' ? " %s: %s\n" : " %s: \"%s\"\n"); |
| 86 | $ret .= sprintf($format, $target, $string); |
| 87 | } |
| 88 | } |
| 89 | else { |
| 90 | $ret .= " *: \"\"\n"; |
| 91 | } |
| 92 | $ret .= sprintf(" </%s>\n", $field); |
| 93 | } |
| 94 | $ret .= "</phrase>\n"; |
| 95 | return $ret; |
| 96 | } |
| 97 | |
| 98 | function print_head() { |
| 99 | header("Content-type: text/html; charset=UTF-8"); |
| 100 | echo <<<END |
| 101 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 102 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 103 | <html> |
| 104 | <head> |
| 105 | <title>Rockbox Translations</title> |
| 106 | <link rel="stylesheet" href="rockbox.css" /> |
| 107 | </head> |
| 108 | <body> |
| 109 | END; |
| 110 | } |
| 111 | |
| 112 | function print_foot() { |
| 113 | $date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0); |
| 114 | echo <<<END |
| 115 | <hr /> |
| 116 | <a href="http://www.rockbox.org"> |
| 117 | <img src="http://www.rockbox.org/rockbox100.png" border="0" width="100" height="32" alt="www.rockbox.org" title="Rockbox - Open Source Jukebox Firmware" /> |
| 118 | </a> |
| 119 | <small> |
| 120 | Last updated $date. Flags copyright Wikimedia contributors. |
| 121 | </small> |
| 122 | |
| 123 | </body> |
| 124 | </html> |
| 125 | END; |
| 126 | } |
| 127 | ?> |