blob: 74d1d834ef17fb00117dd4ffcd91a6770d45dc6d [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00001<?php
Solomon Peachya0eef362020-04-02 10:05:23 -04002/************************************************************************
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äggqvistb632ed12010-01-30 02:04:47 +000021define("PERL", '/usr/bin/perl');
22define("STATS", 'stats.dat');
23define("VERSIONS", 'versions.dat');
24define("SMALL_FLAGSIZE", '22');
25define("LARGE_FLAGSIZE", '150');
Solomon Peachy337902c2020-04-01 21:44:09 -040026define("SMARTY_PATH", '/usr/share/php/Smarty');
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000027
Jonas Häggqvist02ff9a42010-01-31 01:48:25 +000028require_once('templater.class.php');
Solomon Peachy337902c2020-04-01 21:44:09 -040029$smarty = new templater(SMARTY_PATH);
Jonas Häggqvist02ff9a42010-01-31 01:48:25 +000030$smarty->assign('languages', languageinfo());
31$smarty->assign('updated', file_exists(STATS) ? filemtime(STATS) : 0);
32
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000033function languageinfo() {
34 return parse_ini_file('languages.ini', true);
35}
36
37function 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 Peachya0eef362020-04-02 10:05:23 -040050
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000051 $pos = 'phrase';
Solomon Peachya0eef362020-04-02 10:05:23 -040052
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000053 foreach($lines as $lineno => $line) {
54 $line = trim($line);
Solomon Peachya0eef362020-04-02 10:05:23 -040055
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000056 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 Peachya0eef362020-04-02 10:05:23 -040083 return $phrases;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000084}
85
86function 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 Peachya0eef362020-04-02 10:05:23 -040093
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000094 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
118function print_head() {
119header("Content-type: text/html; charset=UTF-8");
120echo <<<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>
129END;
130}
131
132function print_foot() {
133$date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0);
134echo <<<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>
140Last updated $date. Flags copyright Wikimedia contributors.
141</small>
142
143</body>
144</html>
145END;
146}
147?>