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