blob: d5a88837c338dcc5fa39862a7d7c774288d3d4ca [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 {
38 $filename = sprintf("apps/lang/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i);
39 $i++;
40 } while (file_exists($filename));
41
42 $fp = fopen($filename, 'w');
Solomon Peachya0eef362020-04-02 10:05:23 -040043
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000044 // Write a header if one exists
45 $original_lines = file(sprintf("apps/lang/%s.lang", $_REQUEST['lang']));
46 foreach($original_lines as $i => $line) {
47 if (substr($line, 0, 1) == "<") { break; }
48 fwrite($fp, $line);
49 }
Solomon Peachya0eef362020-04-02 10:05:23 -040050
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000051 $original = parselangfile(sprintf("apps/lang/%s.lang.update", $_REQUEST['lang']));
52 $english = parselangfile("apps/lang/english.lang");
53 print("Copyright by individual Rockbox contributors\n");
Dominik Riebeling091c3242012-05-19 19:12:11 +020054 printf("See\nhttp://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 +000055 print("May be distributed under the terms of the GNU GPL version 2 or later\n");
56 print("This file generated by http://translate.rockbox.org/\n\n");
Dominik Riebeling609de012012-05-19 23:20:18 +020057 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 +000058
59 foreach($original as $id => $phrase) {
60 foreach(array('dest', 'voice') as $type) {
61 if (isset($_POST['phrases'][$id])) {
62 if (isset($_POST['phrases'][$id][$type]))
63 $phrase[$type] = $_POST['phrases'][$id][$type];
64 else
65 unset($phrase[$type]);
66 }
67 }
68 if (strtolower($english[$id]['phrase']['desc']) == "deprecated") {
69 $phrase = $english[$id];
70 }
71 fwrite($fp, printphrase($phrase));
72 }
73 fclose($fp);
74 $cmd = sprintf("/usr/bin/diff -u -B -w apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename);
75 print(shell_exec($cmd));
76}
77
78submit();
79?>