Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 1 | <?php |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 2 | /************************************************************************ |
| 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äggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 20 | header("Content-type: text/plain; charset=UTF-8"); |
| 21 | require_once('common.php'); |
| 22 | mb_internal_encoding("UTF-8"); |
| 23 | |
Dominik Riebeling | f385380 | 2012-05-19 19:39:34 +0200 | [diff] [blame] | 24 | $langs = glob('rockbox/apps/lang/*.lang'); |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 25 | $langname = isset($_GET['lang']) ? $_GET['lang'] : 'HUGHAGHGULUAAUL'; |
| 26 | $cmds = explode(",", isset($_GET['cmd']) ? $_GET['cmd'] : ''); |
| 27 | foreach(array('voice', 'sort', 'empty') as $cmd) { |
| 28 | if (isset($_GET[$cmd]) && $_GET[$cmd] == 'on') { |
| 29 | $cmds[] = $cmd; |
| 30 | } |
| 31 | } |
| 32 | function my_basename(&$i) { $i = basename($i, '.lang'); } |
| 33 | array_walk($langs, 'my_basename'); |
| 34 | |
| 35 | if (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 Riebeling | f385380 | 2012-05-19 19:39:34 +0200 | [diff] [blame] | 38 | $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äggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 40 | $lang = parselangfile($langfile); |
Dominik Riebeling | f385380 | 2012-05-19 19:39:34 +0200 | [diff] [blame] | 41 | $english = parselangfile("rockbox/apps/lang/english.lang"); |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 42 | |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 43 | // 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 Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 51 | |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 52 | // 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 Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 67 | |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 68 | // 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 Riebeling | f385380 | 2012-05-19 19:39:34 +0200 | [diff] [blame] | 73 | $english_ids = array_keys(parselangfile("rockbox/apps/lang/english.lang")); |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 74 | } |
| 75 | if ($a === $b) return 0; |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 76 | return (array_search($a, $english_ids) < array_search($b, $english_ids) ? -1 : 1); |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 77 | } |
| 78 | uksort($lang, 'langsort'); |
| 79 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 80 | |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 81 | $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 | |
| 93 | echo <<<MOO |
| 94 | Copyright by individual Rockbox contributors |
| 95 | See |
Solomon Peachy | 18b7141 | 2020-07-08 21:11:27 -0400 | [diff] [blame] | 96 | https://git.rockbox.org/cgit/rockbox.git/log/apps/lang/$langname.lang |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 97 | for details. |
| 98 | May be distributed under the terms of the GNU GPL version 2 or later |
| 99 | |
| 100 | MOO; |
| 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 Riebeling | f385380 | 2012-05-19 19:39:34 +0200 | [diff] [blame] | 112 | print(shell_exec(sprintf("/usr/bin/diff -u rockbox/apps/lang/%s.lang %s", $langname, $tempname))); |
Jonas Häggqvist | a3e83b5 | 2010-01-31 00:40:10 +0000 | [diff] [blame] | 113 | unlink($tempname); |
| 114 | } |
| 115 | |
| 116 | ?> |