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)) { |
Solomon Peachy | a58f0b0 | 2020-07-26 09:18:50 -0400 | [diff] [blame] | 62 | $subs = explode(',' , $matches[1]); |
| 63 | foreach($subs as $sub) { |
| 64 | $thisphrase[$pos][$sub] = $matches[2]; |
| 65 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 66 | } |
| 67 | elseif ($pos != 'phrase' && preg_match("/^([^:]+): ?\"?([^\"]*)\"?$/", $line, $matches)) { |
Solomon Peachy | a58f0b0 | 2020-07-26 09:18:50 -0400 | [diff] [blame] | 68 | $subs = explode(',' , $matches[1]); |
| 69 | foreach($subs as $sub) { |
| 70 | $thisphrase[$pos][$sub] = $matches[2]; |
| 71 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | switch($line) { |
| 75 | case '</voice>': |
| 76 | case '</dest>': |
| 77 | case '</source>': |
| 78 | case '<phrase>': $pos = 'phrase'; break; |
| 79 | case '</phrase>': |
| 80 | $phrases[$thisphrase['phrase']['id']] = $thisphrase; |
| 81 | $thisphrase = $empty; |
| 82 | $pos = 'lang'; |
| 83 | break; |
| 84 | case '<source>': $pos = 'source'; break; |
| 85 | case '<dest>': $pos = 'dest'; break; |
| 86 | case '<voice>': $pos = 'voice'; break; |
| 87 | } |
| 88 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 89 | return $phrases; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | function printphrase($phrase) { |
| 93 | $ret = ''; |
| 94 | $ret .= sprintf("<phrase>\n id: %s\n desc:%s\n user:%s\n", |
| 95 | $phrase['phrase']['id'], |
| 96 | isset($phrase['phrase']['desc']) && $phrase['phrase']['desc'] != "" ? ' '.$phrase['phrase']['desc'] : '', |
| 97 | isset($phrase['phrase']['user']) && $phrase['phrase']['user'] != "" ? ' '.$phrase['phrase']['user'] : '' |
| 98 | ); |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 99 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 100 | foreach(array('source', 'dest', 'voice') as $field) { |
| 101 | $ret .= sprintf(" <%s>\n", $field); |
| 102 | if (isset($phrase[$field])) { |
| 103 | /* If '*' is empty, we don't catch it on the edit-page */ |
| 104 | if (!isset($phrase[$field]['*'])) { |
| 105 | $ret .= " *: \"\"\n"; |
| 106 | } |
| 107 | foreach($phrase[$field] as $target => $string) { |
| 108 | if ($target == 'desc' || $target == 'user' || $target == 'id') continue; |
| 109 | if (trim($string) == 'none') { $string = 'none'; } |
| 110 | elseif (strtolower(trim($string)) == 'deprecated') { $string = 'deprecated'; } |
| 111 | $format = ($string == 'none' || $string == 'deprecated' ? " %s: %s\n" : " %s: \"%s\"\n"); |
| 112 | $ret .= sprintf($format, $target, $string); |
| 113 | } |
| 114 | } |
| 115 | else { |
| 116 | $ret .= " *: \"\"\n"; |
| 117 | } |
| 118 | $ret .= sprintf(" </%s>\n", $field); |
| 119 | } |
| 120 | $ret .= "</phrase>\n"; |
| 121 | return $ret; |
| 122 | } |
| 123 | |
| 124 | function print_head() { |
| 125 | header("Content-type: text/html; charset=UTF-8"); |
| 126 | echo <<<END |
| 127 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 128 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 129 | <html> |
| 130 | <head> |
| 131 | <title>Rockbox Translations</title> |
| 132 | <link rel="stylesheet" href="rockbox.css" /> |
| 133 | </head> |
| 134 | <body> |
| 135 | END; |
| 136 | } |
| 137 | |
| 138 | function print_foot() { |
| 139 | $date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0); |
| 140 | echo <<<END |
| 141 | <hr /> |
Solomon Peachy | 5a27db8 | 2020-04-22 23:15:19 -0400 | [diff] [blame] | 142 | <a href="//www.rockbox.org"> |
| 143 | <img src="//www.rockbox.org/rockbox100.png" border="0" width="100" height="32" alt="www.rockbox.org" title="Rockbox - Open Source Jukebox Firmware" /> |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 144 | </a> |
| 145 | <small> |
| 146 | Last updated $date. Flags copyright Wikimedia contributors. |
| 147 | </small> |
| 148 | |
| 149 | </body> |
| 150 | </html> |
| 151 | END; |
| 152 | } |
| 153 | ?> |