blob: 10283835e689593ccc4e44b4fb9e4e63be51c252 [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)) {
Solomon Peachya58f0b02020-07-26 09:18:50 -040062 $subs = explode(',' , $matches[1]);
63 foreach($subs as $sub) {
64 $thisphrase[$pos][$sub] = $matches[2];
65 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000066 }
67 elseif ($pos != 'phrase' && preg_match("/^([^:]+): ?\"?([^\"]*)\"?$/", $line, $matches)) {
Solomon Peachya58f0b02020-07-26 09:18:50 -040068 $subs = explode(',' , $matches[1]);
69 foreach($subs as $sub) {
70 $thisphrase[$pos][$sub] = $matches[2];
71 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000072 }
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 Peachya0eef362020-04-02 10:05:23 -040089 return $phrases;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000090}
91
92function 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 Peachya0eef362020-04-02 10:05:23 -040099
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000100 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
124function print_head() {
125header("Content-type: text/html; charset=UTF-8");
126echo <<<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>
135END;
136}
137
138function print_foot() {
139$date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0);
140echo <<<END
141<hr />
Solomon Peachy5a27db82020-04-22 23:15:19 -0400142<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äggqvistb632ed12010-01-30 02:04:47 +0000144</a>
145<small>
146Last updated $date. Flags copyright Wikimedia contributors.
147</small>
148
149</body>
150</html>
151END;
152}
153?>