Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsyoshida2015-10-12 08:02:33 +0000
committersyoshida2015-10-12 08:02:33 +0000
commit90ca1df6d1e7bddb06c3f9a96963b31f540d2351 (patch)
tree03ad5fdbc400e4920439641af7bfe5e6b4257e2a
parentc0180764a0ab91cb9e0bd5d630b12989ff688a4e (diff)
downloadserver-90ca1df6d1e7bddb06c3f9a96963b31f540d2351.tar.gz
server-90ca1df6d1e7bddb06c3f9a96963b31f540d2351.tar.xz
server-90ca1df6d1e7bddb06c3f9a96963b31f540d2351.zip
[470120] it is nice if translation hint will prefer front match.
-rw-r--r--html/callback/getTranslationHints.php61
1 files changed, 39 insertions, 22 deletions
diff --git a/html/callback/getTranslationHints.php b/html/callback/getTranslationHints.php
index 6c06e3e..9ff940a 100644
--- a/html/callback/getTranslationHints.php
+++ b/html/callback/getTranslationHints.php
@@ -8,13 +8,18 @@
*
* Contributors:
* Eclipse Foundation - initial API and implementation
+ * Satoru Yoshida - [470120] it is nice if translation hint will prefer front match.
*******************************************************************************/
require_once("cb_global.php");
-$return = array();
-
$tr_string = getHTTPParameter("tr_string", "POST");
+//if contains ampersand, remove before matching
+$tr_string = preg_replace('/\&/', '', $tr_string, 1);
+if (strlen(trim($tr_string)) < 1) {
+ return false;
+}
+
if(isset($_SESSION['language']) and isset($_SESSION['version']) and isset($_SESSION['project'])){
$language = $_SESSION['language'];
$version = $_SESSION['version'];
@@ -23,53 +28,65 @@ if(isset($_SESSION['language']) and isset($_SESSION['version']) and isset($_SESS
return false;
}
-
-/* $query = "SELECT DISTINCT t.value
- FROM translations as t
- INNER JOIN strings AS s ON s.string_id = t.string_id
- WHERE s.value like '%" . addslashes($tr_string). "%'
- AND t.is_active
- AND t.language_id = '".addslashes($language)."'
- ORDER BY LENGTH(t.value) ASC LIMIT 15";
-*/
-
$train_id = "";
$query = "SELECT train_id FROM release_trains ORDER BY train_version LIMIT 2";
-$res = mysql_query($query,$dbh);
+$res = mysql_query($query,$dbh);
while($line = mysql_fetch_array($res, MYSQL_ASSOC)){
if($train_id != "") {
$train_id .= ",";
- }
- $train_id .= "'" . $line['train_id'] . "'";
+ }
+ $train_id .= "'" . $line['train_id'] . "'";
}
if($train_id == "") {
$train_id = 'kepler';
-}
-
+}
+//At first, performs front match
$query = "SELECT DISTINCT t.value
FROM translations as t
INNER JOIN strings AS s ON s.string_id = t.string_id
INNER JOIN files AS f ON s.file_id = f.file_id
INNER JOIN release_train_projects AS tr ON tr.project_id = f.project_id AND tr.version = f.version
-WHERE s.value like '%" . addslashes($tr_string). "%'
+WHERE s.value like '" . addslashes($tr_string). "%'
AND t.is_active
AND tr.train_id IN (" . $train_id . ")
AND t.language_id = '".addslashes($language)."'
ORDER BY LENGTH(t.value) ASC LIMIT 15";
-# print $query."\n";
$res = mysql_query($query,$dbh);
if(mysql_affected_rows($dbh) > 0) {
echo "<ul>";
while($line = mysql_fetch_array($res, MYSQL_ASSOC)){
- echo "<li>" . $line['value'] . "</li>";
+ echo "<li>", $line['value'], "</li>";
}
echo "</ul>";
}
else {
- echo "No hints found. Press [clear] to start over.";
-}
+ //At second, performs partial match
+ $query2 = "SELECT DISTINCT t.value
+ FROM translations as t
+ INNER JOIN strings AS s ON s.string_id = t.string_id
+ INNER JOIN files AS f ON s.file_id = f.file_id
+ INNER JOIN release_train_projects AS tr ON tr.project_id = f.project_id AND tr.version = f.version
+ WHERE s.value like '%" . addslashes($tr_string). "%'
+ AND t.is_active
+ AND tr.train_id IN (" . $train_id . ")
+ AND t.language_id = '".addslashes($language)."'
+ ORDER BY LENGTH(t.value) ASC LIMIT 15";
+
+ $res = mysql_query($query2,$dbh);
+ if(mysql_affected_rows($dbh) > 0) {
+ echo "<ul>";
+ while($line = mysql_fetch_array($res, MYSQL_ASSOC)){
+ echo "<li>", $line['value'], "</li>";
+ }
+ echo "</ul>";
+ }
+ else {
+ echo "No hints found. Press [clear] to start over.";
+ }
+
+}
?> \ No newline at end of file

Back to the top