blob: 9d18e5fc536e84fdbe8d060e66d86ac70f800d4f [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
Solomon Peachy7f1ee2d2021-12-17 10:41:27 -050037function parselangfile($filename, $all = false) {
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000038 $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
Solomon Peachy7f1ee2d2021-12-17 10:41:27 -050056 if ($all == true) {
57 $thisphrase['notes'][0] = "All fields are editable";
58 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000059 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 Peachy18ec0352020-07-26 19:59:29 -040064 elseif (preg_match("/^ *#/", $line, $matches)) {
65 continue;
66 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000067 elseif ($pos == 'phrase' && preg_match("/^([^:]+): ?(.*)$/", $line, $matches)) {
Solomon Peachy38ee3ba2020-07-27 13:17:49 -040068 $thisphrase[$pos][$matches[1]] = $matches[2];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000069 }
70 elseif ($pos != 'phrase' && preg_match("/^([^:]+): ?\"?([^\"]*)\"?$/", $line, $matches)) {
Solomon Peachya58f0b02020-07-26 09:18:50 -040071 $subs = explode(',' , $matches[1]);
72 foreach($subs as $sub) {
Solomon Peachy59431d82020-07-26 20:14:06 -040073 $sub = trim($sub);
Solomon Peachya58f0b02020-07-26 09:18:50 -040074 $thisphrase[$pos][$sub] = $matches[2];
75 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000076 }
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 Peachya0eef362020-04-02 10:05:23 -040093 return $phrases;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000094}
95
Solomon Peachyb61343c2020-07-27 15:59:47 -040096function 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äggqvistb632ed12010-01-30 02:04:47 +0000117function 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 Peachya0eef362020-04-02 10:05:23 -0400124
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000125 foreach(array('source', 'dest', 'voice') as $field) {
126 $ret .= sprintf(" <%s>\n", $field);
127 if (isset($phrase[$field])) {
Solomon Peachyb61343c2020-07-27 15:59:47 -0400128 $phrase[$field] = combinetgts($phrase[$field]);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +0000129 /* 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
150function print_head() {
151header("Content-type: text/html; charset=UTF-8");
152echo <<<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>
161END;
162}
163
164function print_foot() {
165$date = date('D M j H:i:s T Y', file_exists(STATS) ? filemtime(STATS) : 0);
166echo <<<END
167<hr />
Solomon Peachy5a27db82020-04-22 23:15:19 -0400168<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äggqvistb632ed12010-01-30 02:04:47 +0000170</a>
171<small>
172Last updated $date. Flags copyright Wikimedia contributors.
173</small>
174
175</body>
176</html>
177END;
178}
179?>