1<?php
2
3include ('includes/session.php');
4$Title = _('Translate Item Descriptions');
5$ViewTopic = 'SpecialUtilities'; // Filename in ManualContents.php's TOC.
6$BookMark = 'Z_TranslateItemDescriptions'; // Anchor's id in the manual's html document.
7include ('includes/header.php');
8
9if (!function_exists("curl_init")){
10	prnMsg("This script requires that the PHP curl module be available to use the Google API. Unfortunately this installation does not have the curl module available","error");
11	include('includes/footer.php');
12	exit;
13}
14
15include ('includes/GoogleTranslator.php');
16
17$SourceLanguage=mb_substr($_SESSION['Language'],0,2);
18
19// Select items and classify them
20$SQL = "SELECT stockmaster.stockid,
21				description,
22				longdescription,
23				language_id,
24				descriptiontranslation,
25				longdescriptiontranslation
26		FROM stockmaster, stockdescriptiontranslations
27		WHERE stockmaster.stockid = stockdescriptiontranslations.stockid
28			AND stockmaster.discontinued = 0
29			AND (descriptiontranslation = ''
30				OR longdescriptiontranslation = '')
31		ORDER BY stockmaster.stockid,
32				language_id";
33$result = DB_query($SQL);
34
35if(DB_num_rows($result) != 0) {
36	echo '<p class="page_title_text"><strong>' . _('Description Automatic Translation for empty translations') . '</strong></p>';
37	echo '<div>';
38	echo '<table class="selection">';
39	$TableHeader = '<tr>
40						<th>' . _('#') . '</th>
41						<th>' . _('Code') . '</th>
42						<th>' . _('Description') . '</th>
43						<th>' . _('To') . '</th>
44						<th>' . _('Translated') . '</th>
45					</tr>';
46	echo $TableHeader;
47	$i = 0;
48	while ($myrow = DB_fetch_array($result)) {
49
50		if ($myrow['descriptiontranslation'] == ''){
51			$TargetLanguage=mb_substr($myrow['language_id'],0,2);
52			$TranslatedText = translate_via_google_translator($myrow['description'],$TargetLanguage,$SourceLanguage);
53
54			$sql = "UPDATE stockdescriptiontranslations " .
55					"SET descriptiontranslation='" . $TranslatedText . "', " .
56						"needsrevision= '1' " .
57					"WHERE stockid='" . $myrow['stockid'] . "' AND (language_id='" . $myrow['language_id'] . "')";
58			$update = DB_query($sql, $ErrMsg, $DbgMsg, true);
59
60			$i++;
61			printf('<tr class="striped_row">
62					<td class="number">%s</td>
63					<td>%s</td>
64					<td>%s</td>
65					<td>%s</td>
66					<td>%s</td>
67					</tr>',
68					$i,
69					$myrow['stockid'],
70					$myrow['description'],
71					$myrow['language_id'],
72					$TranslatedText
73					);
74		}
75		if ($myrow['longdescriptiontranslation'] == ''){
76			$TargetLanguage=mb_substr($myrow['language_id'],0,2);
77			$TranslatedText = translate_via_google_translator($myrow['longdescription'],$TargetLanguage,$SourceLanguage);
78
79			$sql = "UPDATE stockdescriptiontranslations " .
80					"SET longdescriptiontranslation='" . $TranslatedText . "', " .
81						"needsrevision= '1' " .
82					"WHERE stockid='" . $myrow['stockid'] . "' AND (language_id='" . $myrow['language_id'] . "')";
83			$update = DB_query($sql, $ErrMsg, $DbgMsg, true);
84
85			$i++;
86			printf('<tr class="striped_row">
87					<td class="number">%s</td>
88					<td>%s</td>
89					<td>%s</td>
90					<td>%s</td>
91					<td>%s</td>
92					</tr>',
93					$i,
94					$myrow['stockid'],
95					$myrow['longdescription'],
96					$myrow['language_id'],
97					$TranslatedText
98					);
99		}
100	}
101	echo '</table>
102			</div>';
103	prnMsg(_('Number of translated descriptions via Google API') . ': ' . locale_number_format($i));
104} else {
105
106echo '<p class="page_title_text"><img alt="" src="' . $RootPath . '/css/' . $Theme .
107		'/images/maintenance.png" title="' .
108		_('No item descriptions were automatically translated') . '" />' . ' ' .
109		_('No item descriptions were automatically translated') . '</p>';
110
111// Add error message for "Google Translator API Key" empty.
112
113}
114
115include ('includes/footer.php');
116?>
117