blob: 4b7f7cb5ae5980c22529f94e06174fbb8ad98c1d [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äggqvist04e454b2010-01-31 01:50:52 +000034 chdir('rockbox'); // chdir into the rockbox dir to get proper diffs
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000035
36 $i = 0;
37 do {
Solomon Peachy95b7cdf2020-06-03 21:13:23 -040038 $filename = sprintf("/tmp/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000039 $i++;
40 } while (file_exists($filename));
41
42 $fp = fopen($filename, 'w');
Solomon Peachy95b7cdf2020-06-03 21:13:23 -040043 if ($fp === false) {
44 header("HTTP/1.1 500 Internal Server Error");
45 print "\nUnable to write tmpfile\n";
46 exit(1);
47 }
Solomon Peachya0eef362020-04-02 10:05:23 -040048
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000049 // Write a header if one exists
50 $original_lines = file(sprintf("apps/lang/%s.lang", $_REQUEST['lang']));
51 foreach($original_lines as $i => $line) {
52 if (substr($line, 0, 1) == "<") { break; }
53 fwrite($fp, $line);
54 }
Solomon Peachya0eef362020-04-02 10:05:23 -040055
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000056 $original = parselangfile(sprintf("apps/lang/%s.lang.update", $_REQUEST['lang']));
57 $english = parselangfile("apps/lang/english.lang");
58 print("Copyright by individual Rockbox contributors\n");
Solomon Peachy95b7cdf2020-06-03 21:13:23 -040059 printf("See\nhttps://git.rockbox.org/?p=rockbox.git;a=history;f=apps/lang/%s.lang;hb=HEAD\nfor details.\n", $_REQUEST['lang']);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000060 print("May be distributed under the terms of the GNU GPL version 2 or later\n");
61 print("This file generated by http://translate.rockbox.org/\n\n");
Dominik Riebeling609de012012-05-19 23:20:18 +020062 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 +000063
64 foreach($original as $id => $phrase) {
65 foreach(array('dest', 'voice') as $type) {
66 if (isset($_POST['phrases'][$id])) {
67 if (isset($_POST['phrases'][$id][$type]))
68 $phrase[$type] = $_POST['phrases'][$id][$type];
69 else
70 unset($phrase[$type]);
71 }
72 }
73 if (strtolower($english[$id]['phrase']['desc']) == "deprecated") {
74 $phrase = $english[$id];
75 }
76 fwrite($fp, printphrase($phrase));
77 }
78 fclose($fp);
79 $cmd = sprintf("/usr/bin/diff -u -B -w apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename);
80 print(shell_exec($cmd));
81}
82
83submit();
84?>