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