blob: 26b83c69d477213af1dbcb986fbc07e7a5b9b9ea [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +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 **************************************************************************/
20
21error_reporting(E_ALL);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000022require_once('common.php');
23
24function submit() {
25 header("Content-type: text/plain;charset=UTF-8");
26 header(sprintf("Content-Disposition: attachment; filename=%s.diff", $_REQUEST['lang']));
Dominik Riebeling609de012012-05-19 23:20:18 +020027 $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äggqvistb632ed12010-01-30 02:04:47 +000034
35 $i = 0;
36 do {
Solomon Peachy95b7cdf2020-06-03 21:13:23 -040037 $filename = sprintf("/tmp/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000038 $i++;
39 } while (file_exists($filename));
40
41 $fp = fopen($filename, 'w');
Solomon Peachy95b7cdf2020-06-03 21:13:23 -040042 if ($fp === false) {
43 header("HTTP/1.1 500 Internal Server Error");
44 print "\nUnable to write tmpfile\n";
45 exit(1);
46 }
Solomon Peachya0eef362020-04-02 10:05:23 -040047
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000048 // Write a header if one exists
Solomon Peachyb61343c2020-07-27 15:59:47 -040049 $original_lines = file(sprintf("rockbox/apps/lang/%s.lang", $_REQUEST['lang']));
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000050 foreach($original_lines as $i => $line) {
51 if (substr($line, 0, 1) == "<") { break; }
52 fwrite($fp, $line);
53 }
Solomon Peachya0eef362020-04-02 10:05:23 -040054
Solomon Peachyb61343c2020-07-27 15:59:47 -040055 $original = parselangfile(sprintf("scratch/%s.lang.update", $_REQUEST['lang']));
56 $english = parselangfile("scratch/english.lang");
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000057 print("Copyright by individual Rockbox contributors\n");
Solomon Peachy18b71412020-07-08 21:11:27 -040058 printf("See\nhttps://git.rockbox.org/cgit/rockbox.git/log/apps/lang/%s.lang\nfor details.\n", $_REQUEST['lang']);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000059 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 Riebeling609de012012-05-19 23:20:18 +020061 printf("This translation was based on git hash %s of the original.\n\n", $langs[$_REQUEST['lang']]);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000062
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 Peachyb61343c2020-07-27 15:59:47 -040078 $cmd = sprintf("/usr/bin/diff -u -B -w rockbox/apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000079 print(shell_exec($cmd));
80}
81
82submit();
83?>