1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14// Param: 'id' or 'label'
15function smarty_function_interactivetranslation($params, $smarty)
16{
17	$headerlib = TikiLib::lib('header');
18
19	$strings = get_collected_strings();
20	if (count($strings) == 0) {
21		return;
22	}
23
24	usort($strings, 'sort_strings_by_length');
25
26	$strings = json_encode($strings);
27
28	// add wrench icon link
29	$smarty->loadPlugin('smarty_block_self_link');
30	$help .= smarty_block_self_link(
31		[
32			'_icon' => 'wrench',
33			'_script' => 'tiki-edit_languages.php',
34			'_title' => tra('Click here to go to Edit Languages')
35		],
36		'',
37		$smarty
38	);
39
40	$jq = <<<JS
41	var data = $strings;
42JS;
43
44	$headerlib->add_jq_onready($jq);
45	$headerlib->add_jq_onready(file_get_contents('lib/language/js/interactive_translation.js'));
46
47	return $smarty->fetch('interactive_translation_box.tpl');
48}
49
50function sort_strings_by_length($a, $b)
51{
52	$a = strlen($a[1]);
53	$b = strlen($b[1]);
54
55	if ($a == $b) {
56		return 0;
57	} elseif ($a > $b) {
58		return -1;
59	} else {
60		return 1;
61	}
62}
63