aboutsummaryrefslogtreecommitdiff
path: root/mod/translation_editor/views/default/translation_editor/plugin_edit.php
blob: 113813a2a4d1a5abcd00c518dfa67c49104999d6 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php 
	$current_language = $vars['current_language'];
	$english = $vars['translation']['en'];
	$translated_language = $vars['translation']['current_language'];
	$custom = $vars['translation']['custom'];
	
	$en_flag_file = "mod/translation_editor/_graphics/flags/en.png";
	
	if(file_exists(elgg_get_root_path() . $en_flag_file)){
		$en_flag = "<img src='" . $vars['url'] . $en_flag_file . "' alt='" . elgg_echo("en") . "' title='" . elgg_echo("en") . "'>";
	} else {
		$en_flag = "en";
	}
	
	$lang_flag_file = "mod/translation_editor/_graphics/flags/" . $current_language . ".png";
	
	if(file_exists(elgg_get_root_path() . $lang_flag_file)){
		$lang_flag = "<img src='" . $vars['url'] . $lang_flag_file . "' alt='" . elgg_echo($current_language)  . "' title='" . elgg_echo($current_language) . "'>";
	} else {
		$lang_flag = $current_language;
	}
	
	$missing_count = 0;
	$equal_count = 0;
	$params_count = 0;
	$custom_count = 0;
	
	foreach($english as $en_key => $en_value){
		$en_params = translation_editor_get_string_parameters($en_value);
		$cur_params = translation_editor_get_string_parameters($translated_language[$en_key]);
		
		if(!array_key_exists($en_key, $translated_language)){
			$row_rel = "rel='missing'";
			$missing_count++;
		} elseif($en_value == $translated_language[$en_key]){
			$row_rel = "rel='equal'";
			$equal_count++;
		} elseif($en_params != $cur_params){
			$row_rel = "rel='params'";
			$params_count++;
		} elseif(array_key_exists($en_key, $custom)){
			$row_rel = "rel='custom'";
			$custom_count++;
		} else {
			$row_rel = "";
		}
		
		// English information
		$translation .= "<tr " . $row_rel . ">";
		$translation .= "<td>" . $en_flag . "</td>";
		$translation .= "<td>";
		$translation .= "<span class='translation_editor_plugin_key' title='" . $en_key . "'></span>";
		$translation .= "<pre class='translation_editor_pre'>" . nl2br(htmlspecialchars($en_value)) . "</pre>";
		$translation .="</td>";
		$translation .= "</tr>";
		
		// Custom language information
		$translation .= "<tr ". $row_rel . ">";
		$translation .= "<td>" . $lang_flag . "</td>";
		$translation .= "<td>";
		$translation .= "<textarea name='translation[" . $en_key . "]' >";
		$translation .= $translated_language[$en_key];
		$translation .= "</textarea>";
		$translation .= "</td>";
		$translation .= "</tr>";
	}
	
	$selected_view_mode = "missing";
	
	if($missing_count == 0){
		$selected_view_mode = "all";
		?>
		<style type="text/css">
			.translation_editor_translation_table tr {
				display: table-row;
				<!-- 
				display: inline-block;
				-->
			}
		</style>
		<?php 
	}

	$toggle = "<span id='translation_editor_plugin_toggle' class='float-alt'>";
		
	$toggle .= elgg_echo("translation_editor:plugin_edit:show") . " ";
	
	$missing_class = "";
	$equal_class = "";
	$params_class = "";
	$custom_class = "";
	$all_class = "";
	
	switch($selected_view_mode){
		case "missing":
			$missing_class = "view_mode_active";
			break;
		case "all":
			$all_class = "view_mode_active";
			break;
		case "equal":
			$equal_class = "view_mode_active";
			break;
		case "custom":
			$custom_class = "view_mode_active";
			break;
		case "params":
			$params_class = "view_mode_active";
			break;
	}
	
	$toggle .= "<a class='$missing_class' id='view_mode_missing' href='javascript:toggleViewMode(\"missing\");'>" . elgg_echo("translation_editor:plugin_edit:show:missing") . "</a> (" . $missing_count . "), ";
	$toggle .= "<a class='$equal_class' id='view_mode_equal' href='javascript:toggleViewMode(\"equal\");'>" . elgg_echo("translation_editor:plugin_edit:show:equal") . "</a> (" . $equal_count . "), ";
	$toggle .= "<a class='$params_class' id='view_mode_params' href='javascript:toggleViewMode(\"params\");'>" . elgg_echo("translation_editor:plugin_edit:show:params") . "</a> (" . $params_count . "), ";
	$toggle .= "<a class='$custom_class' id='view_mode_custom' href='javascript:toggleViewMode(\"custom\");'>" . elgg_echo("translation_editor:plugin_edit:show:custom") . "</a> (" . $custom_count . "), ";
	$toggle .= "<a class='$all_class' id='view_mode_all' href='javascript:toggleViewMode(\"all\");'>" . elgg_echo("translation_editor:plugin_edit:show:all") . "</a> (" . $vars['translation']['total'] . ")";
	$toggle .= "</span>";
	
	$list .= "<table class='elgg-table translation_editor_translation_table'>";
	$list .= "<col class='first_col'/>";
	$list .= "<tr class='first_row'><th colspan='2'>";
	$list .= $toggle;
	$list .= elgg_echo("translation_editor:plugin_edit:title") . " " . $vars['plugin'];
	$list .= "</th></tr>";
	$list .= $translation;
	$list .= "</table>";
	
?>
<script type="text/javascript">
	$(document).ready(function(){
		$('#translation_editor_plugin_form textarea').live("change", function(){
			translationEditorJQuerySave();
		});
	});
</script>

<div>
	<form id="translation_editor_plugin_form" action="<?php echo $vars['url'];?>action/translation_editor/translate" method="post">
		<?php echo elgg_view("input/securitytoken"); ?>
		<input type='hidden' name='current_language' value='<?php echo $current_language; ?>' />
		<input type='hidden' name='plugin' value='<?php echo $vars['plugin']; ?>' />
		<?php 
			echo $list;
			echo elgg_view("input/submit", array("value" => elgg_echo("save")));
		?>	
	</form>
</div>