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'); |
Solomon Peachy | 817a336 | 2020-07-27 13:27:53 -0400 | [diff] [blame] | 22 | define("STATS", 'scratch/stats.dat'); |
| 23 | define("VERSIONS", 'scratch/versions.dat'); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 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 | |
Solomon Peachy | 7f1ee2d | 2021-12-17 10:41:27 -0500 | [diff] [blame] | 37 | function parselangfile($filename, $all = false) { |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 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 | |
Solomon Peachy | 7f1ee2d | 2021-12-17 10:41:27 -0500 | [diff] [blame] | 56 | if ($all == true) { |
| 57 | $thisphrase['notes'][0] = "All fields are editable"; |
| 58 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 59 | if (preg_match("/^### (.*)$/", $line, $matches)) { |
| 60 | if (strpos($matches[1], "The phrase is not used. Skipped") === false) { |
| 61 | $thisphrase['notes'][] = $matches[1]; |
| 62 | } |
| 63 | } |
Solomon Peachy | 18ec035 | 2020-07-26 19:59:29 -0400 | [diff] [blame] | 64 | elseif (preg_match("/^ *#/", $line, $matches)) { |
| 65 | continue; |
| 66 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 67 | elseif ($pos == 'phrase' && preg_match("/^([^:]+): ?(.*)$/", $line, $matches)) { |
Solomon Peachy | 38ee3ba | 2020-07-27 13:17:49 -0400 | [diff] [blame] | 68 | $thisphrase[$pos][$matches[1]] = $matches[2]; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 69 | } |
| 70 | elseif ($pos != 'phrase' && preg_match("/^([^:]+): ?\"?([^\"]*)\"?$/", $line, $matches)) { |
Solomon Peachy | a58f0b0 | 2020-07-26 09:18:50 -0400 | [diff] [blame] | 71 | $subs = explode(',' , $matches[1]); |
| 72 | foreach($subs as $sub) { |
Solomon Peachy | 59431d8 | 2020-07-26 20:14:06 -0400 | [diff] [blame] | 73 | $sub = trim($sub); |
Solomon Peachy | a58f0b0 | 2020-07-26 09:18:50 -0400 | [diff] [blame] | 74 | $thisphrase[$pos][$sub] = $matches[2]; |
| 75 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | switch($line) { |
| 79 | case '</voice>': |
| 80 | case '</dest>': |
| 81 | case '</source>': |
| 82 | case '<phrase>': $pos = 'phrase'; break; |
| 83 | case '</phrase>': |
| 84 | $phrases[$thisphrase['phrase']['id']] = $thisphrase; |
| 85 | $thisphrase = $empty; |
| 86 | $pos = 'lang'; |
| 87 | break; |
| 88 | case '<source>': $pos = 'source'; break; |
| 89 | case '<dest>': $pos = 'dest'; break; |
| 90 | case '<voice>': $pos = 'voice'; break; |
| 91 | } |
| 92 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 93 | return $phrases; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 96 | function combinetgts($tgtmap) { |
| 97 | $strmap = array(); |
| 98 | $combined = array(); |
| 99 | |
| 100 | foreach($tgtmap as $tgt => $string) { |
| 101 | if ($tgt == '*') { continue; } |
| 102 | if (isset($strmap[$string])) { |
| 103 | $strmap[$string] .= ",$tgt"; |
| 104 | } else { |
| 105 | $strmap[$string] = "$tgt"; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | $combined['*'] = $tgtmap['*']; |
| 110 | foreach ($strmap as $string => $tgt) { |
| 111 | $combined[$tgt] = $string; |
| 112 | } |
| 113 | |
| 114 | return $combined; |
| 115 | } |
| 116 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 117 | function printphrase($phrase) { |
| 118 | $ret = ''; |
| 119 | $ret .= sprintf("<phrase>\n id: %s\n desc:%s\n user:%s\n", |
| 120 | $phrase['phrase']['id'], |
| 121 | isset($phrase['phrase']['desc']) && $phrase['phrase']['desc'] != "" ? ' '.$phrase['phrase']['desc'] : '', |
| 122 | isset($phrase['phrase']['user']) && $phrase['phrase']['user'] != "" ? ' '.$phrase['phrase']['user'] : '' |
| 123 | ); |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 124 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 125 | foreach(array('source', 'dest', 'voice') as $field) { |
| 126 | $ret .= sprintf(" <%s>\n", $field); |
| 127 | if (isset($phrase[$field])) { |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 128 | $phrase[$field] = combinetgts($phrase[$field]); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 129 | /* If '*' is empty, we don't catch it on the edit-page */ |
| 130 | if (!isset($phrase[$field]['*'])) { |
| 131 | $ret .= " *: \"\"\n"; |
| 132 | } |
| 133 | foreach($phrase[$field] as $target => $string) { |
| 134 | if ($target == 'desc' || $target == 'user' || $target == 'id') continue; |
| 135 | if (trim($string) == 'none') { $string = 'none'; } |
| 136 | elseif (strtolower(trim($string)) == 'deprecated') { $string = 'deprecated'; } |
| 137 | $format = ($string == 'none' || $string == 'deprecated' ? " %s: %s\n" : " %s: \"%s\"\n"); |
| 138 | $ret .= sprintf($format, $target, $string); |
| 139 | } |
| 140 | } |
| 141 | else { |
| 142 | $ret .= " *: \"\"\n"; |
| 143 | } |
| 144 | $ret .= sprintf(" </%s>\n", $field); |
| 145 | } |
| 146 | $ret .= "</phrase>\n"; |
| 147 | return $ret; |
| 148 | } |
| 149 | |
| 150 | function print_head() { |
| 151 | header("Content-type: text/html; charset=UTF-8"); |
| 152 | echo <<<END |
| 153 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 154 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 155 | <html> |
| 156 | <head> |
| 157 | <title>Rockbox Translations</title> |
| 158 | <link rel="stylesheet" href="rockbox.css" /> |
| 159 | </head> |
| 160 | <body> |
| 161 | END; |
| 162 | } |
| 163 | |
| 164 | function print_foot() { |
| 165 | $date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0); |
| 166 | echo <<<END |
| 167 | <hr /> |
Solomon Peachy | 5a27db8 | 2020-04-22 23:15:19 -0400 | [diff] [blame] | 168 | <a href="//www.rockbox.org"> |
| 169 | <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] | 170 | </a> |
| 171 | <small> |
| 172 | Last updated $date. Flags copyright Wikimedia contributors. |
| 173 | </small> |
| 174 | |
| 175 | </body> |
| 176 | </html> |
| 177 | END; |
| 178 | } |
| 179 | ?> |