blob: 0d5bb110da1b57b2ce26a8c99a4ac356657f1120 [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');
Solomon Peachy817a3362020-07-27 13:27:53 -040022define("STATS", 'scratch/stats.dat');
23define("VERSIONS", 'scratch/versions.dat');
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000024define("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 }
Solomon Peachy18ec0352020-07-26 19:59:29 -040061 elseif (preg_match("/^ *#/", $line, $matches)) {
62 continue;
63 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000064 elseif ($pos == 'phrase' && preg_match("/^([^:]+): ?(.*)$/", $line, $matches)) {
Solomon Peachy38ee3ba2020-07-27 13:17:49 -040065 $thisphrase[$pos][$matches[1]] = $matches[2];
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) {
Solomon Peachy59431d82020-07-26 20:14:06 -040070 $sub = trim($sub);
Solomon Peachya58f0b02020-07-26 09:18:50 -040071 $thisphrase[$pos][$sub] = $matches[2];
72 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000073 }
74
75 switch($line) {
76 case '</voice>':
77 case '</dest>':
78 case '</source>':
79 case '<phrase>': $pos = 'phrase'; break;
80 case '</phrase>':
81 $phrases[$thisphrase['phrase']['id']] = $thisphrase;
82 $thisphrase = $empty;
83 $pos = 'lang';
84 break;
85 case '<source>': $pos = 'source'; break;
86 case '<dest>': $pos = 'dest'; break;
87 case '<voice>': $pos = 'voice'; break;
88 }
89 }
Solomon Peachya0eef362020-04-02 10:05:23 -040090 return $phrases;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000091}
92
Solomon Peachyb61343c2020-07-27 15:59:47 -040093function combinetgts($tgtmap) {
94 $strmap = array();
95 $combined = array();
96
97 foreach($tgtmap as $tgt => $string) {
98 if ($tgt == '*') { continue; }
99 if (isset($strmap[$string])) {
100 $strmap[$string] .= ",$tgt";
101 } else {
102 $strmap[$string] = "$tgt";
103 }
104 }
105
106 $combined['*'] = $tgtmap['*'];
107 foreach ($strmap as $string => $tgt) {
108 $combined[$tgt] = $string;
109 }
110
111 return $combined;
112}
113
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000114function printphrase($phrase) {
115 $ret = '';
116 $ret .= sprintf("<phrase>\n id: %s\n desc:%s\n user:%s\n",
117 $phrase['phrase']['id'],
118 isset($phrase['phrase']['desc']) && $phrase['phrase']['desc'] != "" ? ' '.$phrase['phrase']['desc'] : '',
119 isset($phrase['phrase']['user']) && $phrase['phrase']['user'] != "" ? ' '.$phrase['phrase']['user'] : ''
120 );
Solomon Peachya0eef362020-04-02 10:05:23 -0400121
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000122 foreach(array('source', 'dest', 'voice') as $field) {
123 $ret .= sprintf(" <%s>\n", $field);
124 if (isset($phrase[$field])) {
Solomon Peachyb61343c2020-07-27 15:59:47 -0400125 $phrase[$field] = combinetgts($phrase[$field]);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000126 /* If '*' is empty, we don't catch it on the edit-page */
127 if (!isset($phrase[$field]['*'])) {
128 $ret .= " *: \"\"\n";
129 }
130 foreach($phrase[$field] as $target => $string) {
131 if ($target == 'desc' || $target == 'user' || $target == 'id') continue;
132 if (trim($string) == 'none') { $string = 'none'; }
133 elseif (strtolower(trim($string)) == 'deprecated') { $string = 'deprecated'; }
134 $format = ($string == 'none' || $string == 'deprecated' ? " %s: %s\n" : " %s: \"%s\"\n");
135 $ret .= sprintf($format, $target, $string);
136 }
137 }
138 else {
139 $ret .= " *: \"\"\n";
140 }
141 $ret .= sprintf(" </%s>\n", $field);
142 }
143 $ret .= "</phrase>\n";
144 return $ret;
145}
146
147function print_head() {
148header("Content-type: text/html; charset=UTF-8");
149echo <<<END
150<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
151 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
152<html>
153<head>
154<title>Rockbox Translations</title>
155<link rel="stylesheet" href="rockbox.css" />
156</head>
157<body>
158END;
159}
160
161function print_foot() {
162$date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0);
163echo <<<END
164<hr />
Solomon Peachy5a27db82020-04-22 23:15:19 -0400165<a href="//www.rockbox.org">
166 <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 +0000167</a>
168<small>
169Last updated $date. Flags copyright Wikimedia contributors.
170</small>
171
172</body>
173</html>
174END;
175}
176?>