summaryrefslogtreecommitdiff
path: root/translator/index.php
blob: 1f09734fb79cb3a23b61118aaba200b5ace9f4da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php header("Content-Type: text/html; charset=UTF-8"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="et">
<head>
<title>RoundCube Translator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
</head>
<body>

<h2 id="pageheader">RoundCube (Live) Translator</h2>

<?php include('func.php'); ?>

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<fieldset>
<legend>What to translate</legend>

<?php echo lang_selection($lang); ?>

<select name="file">
	<option value="labels.inc"<?=($file=='labels.inc'?' selected':'')?>>labels.inc</option>
	<option value="messages.inc"<?=($file=='messages.inc'?' selected':'')?>>messages.inc</option>
</select>

<div>
<input type="checkbox" name="trans" id="trans" value="1"<?=($translated?' checked':'')?> />
<label for="trans">Show translated texts</label>
</div>

<p><input type="submit" class="button" value="Select" /></p>
</fieldset>
</form>

<div id="translations">
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="save" value="1" />
<?php

if (!empty($lang) && !empty($file))
{
	echo '<input type="hidden" name="lang" value="'.$lang.'" /><input type="hidden" name="file" value="'.$file.'" />';
	echo '<input type="hidden" name="trans" value="'.($translated?'1':'').'" />';
	echo '<table border="0" cellspacing="0" class="translist" summary="">';
	echo '<thead><tr><td>Label</td><td>Original</td><td>Translation</td></tr></thead><tbody>';
	
	if ($lang != "_NEW_")
		@include(update_from_svn($lang, $file));
		
	if (!empty($labels))
		$edit_values = $labels;
	else if (!empty($messages))
		$edit_values = $messages;
	else
		$edit_values = array();
	
	$count = 0;
	foreach($orig_values as $t_key => $t_value)
	{
		// skip translated lines
		if(!$translated && !empty($edit_values[$t_key]))
			continue;

		if ($post_value = get_input_value('t_'.$t_key))
			$edit_values[$t_key] = $post_value;

		echo '<tr class="'.(empty($edit_values[$t_key]) ? 'untranslated' : '')."\">\n";
		echo '<td class="key">'.htmlspecialchars($t_key).'</td>';
		echo '<td class="original">'.htmlspecialchars($t_value).'</td>';
		echo '<td><input name="t_'.$t_key.'" value="'.(!empty($edit_values[$t_key]) ? htmlspecialchars($edit_values[$t_key]) : "").'" size="60" />';
		echo "</td>\n</tr>\n";
		
		$count++;
	}
	
	if (!$count)
		echo '<tr><td colspan="3"><em>No new texts to translate</em></td></tr>';
	
	echo "</tbody></table>\n";
	echo '<p><input type="submit" class="button" name="translate" value="Create translation"/></p>';

}

?>
</form>
</div>

<?php

if (isset($_POST["save"]) && $file && $lang)
{
	$array = $file == "messages.inc" ? '$messages' : '$labels';
	$fpath = $lang != "_NEW_" ? update_from_svn($lang, $file) : 'nope';
	
	if (!strstr($fpath, 'http') && !is_file($fpath))
		$fpath = realpath("./$file");
	
	echo '<div id="resultsbox">'."<h3>Localization file</h3>\n";
	echo '<form id="select_all" action="./">
	<textarea id="results" name="text_area" rows="'.min(30, count($orig_values)).'" cols="130">';

	if ($fpath && ($fp = fopen($fpath, 'r')))
	{
		while (!feof($fp))
		{
			$line = fgets($fp);
			echo htmlspecialchars(str_replace('#lang', $lang, rtrim($line))) . "\n";
			if (strstr($line, $array))
				break;
		}
	}
	else
	{
		echo "&lt;?php\n";
		echo $array . " = array();\n";
	}

	foreach($orig_values as $t_key => $t_value)
	{
		$t_value = get_input_value('t_'.$t_key);
		if (empty($t_value) && isset($edit_values[$t_key]))
			$t_value = $edit_values[$t_key];
		if (!empty($t_value))
			echo $array . "['$t_key'] = '" . addslashes(htmlspecialchars($t_value, ENT_COMPAT, 'UTF-8')) . "';\n";
	}

	echo "\n?&gt;</textarea>\n";
	echo '<p><input id="hilight" class="button" type="button" value="Select all" onclick="javascript:this.form.text_area.focus();this.form.text_area.select();" /></p>';
	echo "\n</form></div>";
}

?>
</body>
</html>