blob: 1f6de74e26fa7e1762f79a696df63f6fe834c975 [file] [log] [blame]
Jonas Häggqvista3e83b52010-01-31 00:40:10 +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 **************************************************************************/
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000020header("Content-type: text/plain; charset=UTF-8");
21require_once('common.php');
22mb_internal_encoding("UTF-8");
23
Dominik Riebelingf3853802012-05-19 19:39:34 +020024$langs = glob('rockbox/apps/lang/*.lang');
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000025$langname = isset($_GET['lang']) ? $_GET['lang'] : 'HUGHAGHGULUAAUL';
26$cmds = explode(",", isset($_GET['cmd']) ? $_GET['cmd'] : '');
27foreach(array('voice', 'sort', 'empty') as $cmd) {
28 if (isset($_GET[$cmd]) && $_GET[$cmd] == 'on') {
29 $cmds[] = $cmd;
30 }
31}
32function my_basename(&$i) { $i = basename($i, '.lang'); }
33array_walk($langs, 'my_basename');
34
35if (in_array($langname, $langs)) {
36 if (isset($_GET['sendfile']))
37 header(sprintf("Content-Disposition: attachment; filename=%s-fix-%s.diff", $langname, str_replace('/', '_', implode(',', $cmds))));
Dominik Riebelingf3853802012-05-19 19:39:34 +020038 $langfile = sprintf("rockbox/apps/lang/%s.lang", $langname);
39 $tempname = sprintf('rockbox/apps/lang/%s.lang-fixlang-%s', $langname, uniqid('',$_SERVER['REMOTE_ADDR'].$langname));
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000040 $lang = parselangfile($langfile);
Dominik Riebelingf3853802012-05-19 19:39:34 +020041 $english = parselangfile("rockbox/apps/lang/english.lang");
Solomon Peachya0eef362020-04-02 10:05:23 -040042
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000043 // Copy voice over if English source and voice are the same
44 if (in_array('voice', $cmds)) {
45 foreach($lang as $id => $phrase) {
46 if ($english[$id]['source'] == $english[$id]['voice']) {
47 $lang[$id]['voice'] = $lang[$id]['dest'];
48 }
49 }
50 }
Solomon Peachya0eef362020-04-02 10:05:23 -040051
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000052 // Mirror empty/none strings from English to target
53 if (in_array('empty', $cmds)) {
54 foreach($lang as $id => $phrase) {
55 foreach(array('dest', 'voice') as $what) {
56 foreach($phrase[$what] as $target => $value) {
57 if (!isset($english[$id][$what][$target]))
58 unset($lang[$id][$what][$target]);
59 $e = $english[$id][$what][$target];
60 if ($e == 'none' || $e == 'deprecated' || $e == "") {
61 $lang[$id][$what][$target] = $e;
62 }
63 }
64 }
65 }
66 }
Solomon Peachya0eef362020-04-02 10:05:23 -040067
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000068 // Sort language in English order
69 if (in_array('sort', $cmds)) {
70 function langsort($a, $b) {
71 static $english_ids = true;
72 if ($english_ids === true) {
Dominik Riebelingf3853802012-05-19 19:39:34 +020073 $english_ids = array_keys(parselangfile("rockbox/apps/lang/english.lang"));
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000074 }
75 if ($a === $b) return 0;
Solomon Peachya0eef362020-04-02 10:05:23 -040076 return (array_search($a, $english_ids) < array_search($b, $english_ids) ? -1 : 1);
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000077 }
78 uksort($lang, 'langsort');
79 }
Solomon Peachya0eef362020-04-02 10:05:23 -040080
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000081 $fp = fopen($tempname, 'w');
82 // Print header
83 foreach(file($langfile) as $line) {
84 if (substr($line, 0, 1) != '#') break;
85 fwrite($fp, $line);
86 }
87 // Print all phrases
88 foreach($lang as $id => $phrase) {
89 fwrite($fp, printphrase($phrase));
90 }
91 fclose($fp);
92
93echo <<<MOO
94Copyright by individual Rockbox contributors
95See
Solomon Peachy18b71412020-07-08 21:11:27 -040096https://git.rockbox.org/cgit/rockbox.git/log/apps/lang/$langname.lang
Jonas Häggqvista3e83b52010-01-31 00:40:10 +000097for details.
98May be distributed under the terms of the GNU GPL version 2 or later
99
100MOO;
101
102 printf("This diff was generated using http://%s%s\n\n", $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
103 print("The following actions were taken:\n");
104 print(" * Stricter syntax used (uniform whitespace, user field in all phrases)\n");
105 foreach($cmds as $cmd) {
106 switch($cmd) {
107 case 'voice': print(" * Copying dest to voice for phrases where dest and voice are the same\n in english.lang\n"); break;
108 case 'empty': print(" * Make empty and 'none' strings match english.lang\n"); break;
109 case 'sort': print(" * Sorting phrases in the order found in english.lang\n"); break;
110 }
111 }
Dominik Riebelingf3853802012-05-19 19:39:34 +0200112 print(shell_exec(sprintf("/usr/bin/diff -u rockbox/apps/lang/%s.lang %s", $langname, $tempname)));
Jonas Häggqvista3e83b52010-01-31 00:40:10 +0000113 unlink($tempname);
114}
115
116?>