blob: cb2bc9ed5f555332bf3ffa0bfc8ed74fea6166a4 [file] [log] [blame]
Jonas Häggqvista3e83b52010-01-31 00:40:10 +00001<?php
2header("Content-type: text/plain; charset=UTF-8");
3require_once('common.php');
4mb_internal_encoding("UTF-8");
5
Jonas Häggqvista3e83b52010-01-31 00:40:10 +00006$langs = glob('apps/lang/*.lang');
7$langname = isset($_GET['lang']) ? $_GET['lang'] : 'HUGHAGHGULUAAUL';
8$cmds = explode(",", isset($_GET['cmd']) ? $_GET['cmd'] : '');
9foreach(array('voice', 'sort', 'empty') as $cmd) {
10 if (isset($_GET[$cmd]) && $_GET[$cmd] == 'on') {
11 $cmds[] = $cmd;
12 }
13}
14function my_basename(&$i) { $i = basename($i, '.lang'); }
15array_walk($langs, 'my_basename');
16
17if (in_array($langname, $langs)) {
18 if (isset($_GET['sendfile']))
19 header(sprintf("Content-Disposition: attachment; filename=%s-fix-%s.diff", $langname, str_replace('/', '_', implode(',', $cmds))));
20 $langfile = sprintf("apps/lang/%s.lang", $langname);
21 $tempname = sprintf('apps/lang/%s.lang-fixlang-%s', $langname, uniqid('',$_SERVER['REMOTE_ADDR'].$langname));
22 $lang = parselangfile($langfile);
23 $english = parselangfile("apps/lang/english.lang");
24
25 // Copy voice over if English source and voice are the same
26 if (in_array('voice', $cmds)) {
27 foreach($lang as $id => $phrase) {
28 if ($english[$id]['source'] == $english[$id]['voice']) {
29 $lang[$id]['voice'] = $lang[$id]['dest'];
30 }
31 }
32 }
33
34 // Mirror empty/none strings from English to target
35 if (in_array('empty', $cmds)) {
36 foreach($lang as $id => $phrase) {
37 foreach(array('dest', 'voice') as $what) {
38 foreach($phrase[$what] as $target => $value) {
39 if (!isset($english[$id][$what][$target]))
40 unset($lang[$id][$what][$target]);
41 $e = $english[$id][$what][$target];
42 if ($e == 'none' || $e == 'deprecated' || $e == "") {
43 $lang[$id][$what][$target] = $e;
44 }
45 }
46 }
47 }
48 }
49
50 // Sort language in English order
51 if (in_array('sort', $cmds)) {
52 function langsort($a, $b) {
53 static $english_ids = true;
54 if ($english_ids === true) {
55 $english_ids = array_keys(parselangfile("apps/lang/english.lang"));
56 }
57 if ($a === $b) return 0;
58 return (array_search($a, $english_ids) < array_search($b, $english_ids) ? -1 : 1);
59 }
60 uksort($lang, 'langsort');
61 }
62
63 $fp = fopen($tempname, 'w');
64 // Print header
65 foreach(file($langfile) as $line) {
66 if (substr($line, 0, 1) != '#') break;
67 fwrite($fp, $line);
68 }
69 // Print all phrases
70 foreach($lang as $id => $phrase) {
71 fwrite($fp, printphrase($phrase));
72 }
73 fclose($fp);
74
75echo <<<MOO
76Copyright by individual Rockbox contributors
77See
Dominik Riebeling091c3242012-05-19 19:12:11 +020078http://git.rockbox.org/?p=rockbox.git;a=history;f=apps/lang/$langname.lang;hb=HEAD
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000079for details.
80May be distributed under the terms of the GNU GPL version 2 or later
81
82MOO;
83
84 printf("This diff was generated using http://%s%s\n\n", $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
85 print("The following actions were taken:\n");
86 print(" * Stricter syntax used (uniform whitespace, user field in all phrases)\n");
87 foreach($cmds as $cmd) {
88 switch($cmd) {
89 case 'voice': print(" * Copying dest to voice for phrases where dest and voice are the same\n in english.lang\n"); break;
90 case 'empty': print(" * Make empty and 'none' strings match english.lang\n"); break;
91 case 'sort': print(" * Sorting phrases in the order found in english.lang\n"); break;
92 }
93 }
94 print(shell_exec(sprintf("/usr/bin/diff -u apps/lang/%s.lang %s", $langname, $tempname)));
95 unlink($tempname);
96}
97
98?>