mirrored from git://git.rockbox.org/translate.git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixlang.php
116 lines (106 loc) · 4.57 KB
/
fixlang.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* Copyright (C) 2010 Jonas Häggqvist
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
**************************************************************************/
header("Content-type: text/plain; charset=UTF-8");
require_once('common.php');
mb_internal_encoding("UTF-8");
$langs = glob('rockbox/apps/lang/*.lang');
$langname = isset($_GET['lang']) ? $_GET['lang'] : 'HUGHAGHGULUAAUL';
$cmds = explode(",", isset($_GET['cmd']) ? $_GET['cmd'] : '');
foreach(array('voice', 'sort', 'empty') as $cmd) {
if (isset($_GET[$cmd]) && $_GET[$cmd] == 'on') {
$cmds[] = $cmd;
}
}
function my_basename(&$i) { $i = basename($i, '.lang'); }
array_walk($langs, 'my_basename');
if (in_array($langname, $langs)) {
if (isset($_GET['sendfile']))
header(sprintf("Content-Disposition: attachment; filename=%s-fix-%s.diff", $langname, str_replace('/', '_', implode(',', $cmds))));
$langfile = sprintf("rockbox/apps/lang/%s.lang", $langname);
$tempname = sprintf('/tmp/%s.lang-fixlang-%s', $langname, uniqid('',$_SERVER['REMOTE_ADDR'].$langname));
$lang = parselangfile($langfile);
$english = parselangfile("rockbox/apps/lang/english.lang");
// Copy voice over if English source and voice are the same
if (in_array('voice', $cmds)) {
foreach($lang as $id => $phrase) {
if ($english[$id]['source'] == $english[$id]['voice']) {
$lang[$id]['voice'] = $lang[$id]['dest'];
}
}
}
// Mirror empty/none strings from English to target
if (in_array('empty', $cmds)) {
foreach($lang as $id => $phrase) {
foreach(array('dest', 'voice') as $what) {
foreach($phrase[$what] as $target => $value) {
if (!isset($english[$id][$what][$target]))
unset($lang[$id][$what][$target]);
$e = $english[$id][$what][$target];
if ($e == 'none' || $e == 'deprecated' || $e == "") {
$lang[$id][$what][$target] = $e;
}
}
}
}
}
// Sort language in English order
if (in_array('sort', $cmds)) {
function langsort($a, $b) {
static $english_ids = true;
if ($english_ids === true) {
$english_ids = array_keys(parselangfile("rockbox/apps/lang/english.lang"));
}
if ($a === $b) return 0;
return (array_search($a, $english_ids) < array_search($b, $english_ids) ? -1 : 1);
}
uksort($lang, 'langsort');
}
$fp = fopen($tempname, 'w');
// Print header
foreach(file($langfile) as $line) {
if (substr($line, 0, 1) != '#') break;
fwrite($fp, $line);
}
// Print all phrases
foreach($lang as $id => $phrase) {
fwrite($fp, printphrase($phrase));
}
fclose($fp);
echo <<<MOO
Copyright by individual Rockbox contributors
See
https://git.rockbox.org/cgit/rockbox.git/log/apps/lang/$langname.lang
for details.
May be distributed under the terms of the GNU GPL version 2 or later
MOO;
printf("This diff was generated using http://%s%s\n\n", $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
print("The following actions were taken:\n");
print(" * Stricter syntax used (uniform whitespace, user field in all phrases)\n");
foreach($cmds as $cmd) {
switch($cmd) {
case 'voice': print(" * Copying dest to voice for phrases where dest and voice are the same\n in english.lang\n"); break;
case 'empty': print(" * Make empty and 'none' strings match english.lang\n"); break;
case 'sort': print(" * Sorting phrases in the order found in english.lang\n"); break;
}
}
print(shell_exec(sprintf("/usr/bin/diff -u rockbox/apps/lang/%s.lang %s", $langname, $tempname)));
unlink($tempname);
}
?>