blob: b625fee5963d6889841fc3877e04f3c5a1ba6579 [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00001<?php
2define("PERL", '/usr/bin/perl');
3define("STATS", 'stats.dat');
4define("VERSIONS", 'versions.dat');
5define("SMALL_FLAGSIZE", '22');
6define("LARGE_FLAGSIZE", '150');
Solomon Peachy337902c2020-04-01 21:44:09 -04007define("SMARTY_PATH", '/usr/share/php/Smarty');
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00008
Jonas Häggqvist02ff9a42010-01-31 01:48:25 +00009require_once('templater.class.php');
Solomon Peachy337902c2020-04-01 21:44:09 -040010$smarty = new templater(SMARTY_PATH);
Jonas Häggqvist02ff9a42010-01-31 01:48:25 +000011$smarty->assign('languages', languageinfo());
12$smarty->assign('updated', file_exists(STATS) ? filemtime(STATS) : 0);
13
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000014function languageinfo() {
15 return parse_ini_file('languages.ini', true);
16}
17
18function 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
67function 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
99function print_head() {
100header("Content-type: text/html; charset=UTF-8");
101echo <<<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>
110END;
111}
112
113function print_foot() {
114$date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0);
115echo <<<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>
121Last updated $date. Flags copyright Wikimedia contributors.
122</small>
123
124</body>
125</html>
126END;
127}
128?>