Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +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 | **************************************************************************/ |
| 20 | |
| 21 | error_reporting(E_ALL); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 22 | require_once('common.php'); |
| 23 | |
| 24 | function submit() { |
| 25 | header("Content-type: text/plain;charset=UTF-8"); |
| 26 | header(sprintf("Content-Disposition: attachment; filename=%s.diff", $_REQUEST['lang'])); |
Dominik Riebeling | 609de01 | 2012-05-19 23:20:18 +0200 | [diff] [blame] | 27 | $langs = array(); |
| 28 | if (file_exists(VERSIONS)) { |
| 29 | foreach(file(VERSIONS) as $line) { |
| 30 | list($lang, $version) = explode(":", trim($line)); |
| 31 | $langs[$lang] = $version; |
| 32 | } |
| 33 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 34 | |
| 35 | $i = 0; |
| 36 | do { |
Solomon Peachy | 95b7cdf | 2020-06-03 21:13:23 -0400 | [diff] [blame] | 37 | $filename = sprintf("/tmp/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 38 | $i++; |
| 39 | } while (file_exists($filename)); |
| 40 | |
| 41 | $fp = fopen($filename, 'w'); |
Solomon Peachy | 95b7cdf | 2020-06-03 21:13:23 -0400 | [diff] [blame] | 42 | if ($fp === false) { |
| 43 | header("HTTP/1.1 500 Internal Server Error"); |
| 44 | print "\nUnable to write tmpfile\n"; |
| 45 | exit(1); |
| 46 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 47 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 48 | // Write a header if one exists |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 49 | $original_lines = file(sprintf("rockbox/apps/lang/%s.lang", $_REQUEST['lang'])); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 50 | foreach($original_lines as $i => $line) { |
| 51 | if (substr($line, 0, 1) == "<") { break; } |
| 52 | fwrite($fp, $line); |
| 53 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 54 | |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 55 | $original = parselangfile(sprintf("scratch/%s.lang.update", $_REQUEST['lang'])); |
| 56 | $english = parselangfile("scratch/english.lang"); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 57 | print("Copyright by individual Rockbox contributors\n"); |
Solomon Peachy | 18b7141 | 2020-07-08 21:11:27 -0400 | [diff] [blame] | 58 | printf("See\nhttps://git.rockbox.org/cgit/rockbox.git/log/apps/lang/%s.lang\nfor details.\n", $_REQUEST['lang']); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 59 | print("May be distributed under the terms of the GNU GPL version 2 or later\n"); |
| 60 | print("This file generated by http://translate.rockbox.org/\n\n"); |
Dominik Riebeling | 609de01 | 2012-05-19 23:20:18 +0200 | [diff] [blame] | 61 | printf("This translation was based on git hash %s of the original.\n\n", $langs[$_REQUEST['lang']]); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 62 | |
| 63 | foreach($original as $id => $phrase) { |
| 64 | foreach(array('dest', 'voice') as $type) { |
| 65 | if (isset($_POST['phrases'][$id])) { |
| 66 | if (isset($_POST['phrases'][$id][$type])) |
| 67 | $phrase[$type] = $_POST['phrases'][$id][$type]; |
| 68 | else |
| 69 | unset($phrase[$type]); |
| 70 | } |
| 71 | } |
| 72 | if (strtolower($english[$id]['phrase']['desc']) == "deprecated") { |
| 73 | $phrase = $english[$id]; |
| 74 | } |
| 75 | fwrite($fp, printphrase($phrase)); |
| 76 | } |
| 77 | fclose($fp); |
Solomon Peachy | b61343c | 2020-07-27 15:59:47 -0400 | [diff] [blame] | 78 | $cmd = sprintf("/usr/bin/diff -u -B -w rockbox/apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 79 | print(shell_exec($cmd)); |
| 80 | } |
| 81 | |
| 82 | submit(); |
| 83 | ?> |